각각 C++와 Qt 및 HTuple 간의 변환

1. 이미지 처리를 할 때 C++와 QT, Htuple 간의 변환을 자주 접하게 됩니다. 이것은 어렵지 않지만 잊기 쉽습니다. 다시 기록하고 나중에 참조하기 위해 잊어버리십시오.
2. 변환 코드
2.1 C++와 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 QT와 Htuple 간의 상호 변환
qt의 QString도 Htuple로 변환할 수 있지만 먼저 C++로 변환한 다음 Htuple로 변환해야 합니다.

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

추천

출처blog.csdn.net/Douhaoyu/article/details/128418830