HALCON的HTuple类型(元组)功能很强大,可以表示INT、double、string等多种类型数据。当元组中只有一个成员时,HTuple也可表示原子类型
一、HTuple与Int、string、double类型相互转化
//HTuple转int
HTuple hTuple = 1;
int str1 = hTuple[0].I(); // str1 = 1
//HTuple转double 常用
HTuple hTuple = 1.1;
double str2 = hTuple[0].D(); // str2 = 1.1
//HTuple转CString
HTuple hTuple = "cstring";
CString str3 = hTuple[0].S(); // str3 = "cstring"
二、int、double、string转HTuple
int str1 = 1;
double str2 = 1.1;
CString str3 = "CString";
QString str4 = "QString";
HTuple hTuple2;
hTuple2[0] = str1; // hTuple2[0].I() = 1
hTuple2[1] = str2; // hTuple2[1].D() = 1.1
hTuple2[2] = str3.GetBuffer(); // hTuple2[2].S() = "CString"
hTuple2[3] = str4.toStdString().c_str(); // hTuple2[3].S() = "QString"
int i = hTuple2[0].I(); // i=1
double d = hTuple2[1].D(); // d=1.1
CString cstring = hTuple2[2].S(); // cstring = "CString"
QString qstring = hTuple2[3].S(); // qstring = "QString"