qt - Conversion from QString to hex -
i have same code in 2 different projects. qstring::number(data.tolong(&ok,2),16) works in 1 project , in other project not work. know reason be? code follows
1) unsigned short status; 2) long int setting; 3) bool ok; 4) qstring data_selected; 5) data_selected = lineedit_data->text(); //get binary value 6) data_selected = qstring::number(data_selected.tolong(&ok, 2), 16); //convert binary value hex value 7) setting = data_selected.tolong(&ok, 16); //convert string integer
in line 5 getting data lineedit. line works fine. inserted new text edit box , displayed data there , there can see data. have data "1000000000001000". execute line 6, output of '8008' in first case , '0' in other project. problem. code same. have copied , pasted. in debugging can see difference. please can tell me why happening?
i thought comment under answer clear.
correct code detect problem:
ulong setting; bool ok; data_selected = data_selected.trimmed(); // first try without line ulong value = data_selected.toulong(&ok, 2); if (ok) { data_selected = qstring::number(value, 16); setting = data_selected.toulong(&ok, 16); } else { data_selected = "convertion error"; }
Comments
Post a Comment