Conversion between C++ and Qt and HTuple respectively

1. When doing image processing, we often encounter the conversion between C++ and QT and Htuple. This stuff is not difficult, but it is easy to forget. Record it again, and forget it for reference later.
2. Conversion code
2.1 Mutual conversion between C++ and HTuple

	string temp = “D:\\1.jpg”;
	// 1. char* 类型转HTuple
	const char* ctemp = temp.c_str();
	HTuple h_c_temp(ctemp);
	// 检查是否已转化
	string stemp = h_c_temp.S();
	CString visiualTemp = h_c_temp.S();
	
	// 2. temp 是string类型的,string类型转HTuple
	HTuple htemp(temp.c_str());
	// 检查是否已转化
	visiualTemp = htemp.S();
	// cstring类型转HTuple
	Cstring cstr_temp = tmep.c_str();
	HTuple h_cstr_temp(cstr_temp.GetBuffer());
	// 检查是否已转化
	visiualTemp  = h_cstr_temp.S();


//3. HTuple转int
HTuple hTuple = 1;
int str1 =  hTuple[0].I();         // str1 = 1
            
//4. HTuple转double   常用
HTuple hTuple = 1.1;
double str2 = hTuple[0].D();       // str2 = 1.1

//5. HTuple转CString
HTuple hTuple = "cstring";
CString str3 = hTuple[0].S();      // str3 = "cstring"

2.2 Mutual conversion between QT and Htuple
The QString of qt can also be converted to Htuple, but it needs to be converted to C++ first, and then converted to Htuple.

QString str =“D:\\1.jpg”;
const char* ctemp = str.toStdString().c_str(); 
HTuple h_c_temp(ctemp);

Guess you like

Origin blog.csdn.net/Douhaoyu/article/details/128418830