View Full Version : DWORD to QSTRING
digog
8th November 2010, 02:42
Hello,
Has anyone an idea on how to convert a DWORD to a QSTRING to display in a lineEdit?
Thanks
ChrisW67
8th November 2010, 03:14
A DWORD is a typedef for unsigned long in Microsoft headers. Look at the QString::arg() or the QString::number() variants. How do you want to display it?
digog
8th November 2010, 05:17
I want to display it in a QLineEdit. I have a DWORD variable MPUSBGetDLLVersion and I want to display it just like this:
QLineEdit *lineEdit;
lineEdit = new QLineEdit;
lineEdit->setText(MPUSBGetDLLVersion);
but I need to convert the MPUSBGetDLLVersion to a QString first.
I'll take a look at the QString::arg() and the QString::number() variants.
Added after 58 minutes:
Ok, I write the code like this now:
DWORD temp = MPUSBGetDLLVersion();
lineEdit2->setText( tr("MPUSBAPI Version:%1.%2").arg(QString::number( HIWORD(temp),10))
.arg(QString::number(LOWORD(temp),10)));
When I display it I am getting the value MPUSBAPI Version:257.0 instead of MPUSBAPI Version:1.0. Anyone knows what I am doing wrong?
wysota
8th November 2010, 11:56
Looks like you need to shift the higher word to the right (257 = 256+1).
digog
8th November 2010, 14:03
Looks like you need to shift the higher word to the right (257 = 256+1).
How can I do it?
wysota
8th November 2010, 14:04
How can I do it?
Most likely using the C++ binary shift operator.
ChrisW67
8th November 2010, 21:57
From a quick Google it seems the version number is typically output in hexadecimal:
http://www.microchip.com/forums/m346499-print.aspx
temp = MPUSBGetDLLVersion();
cout << "DLL Version => " << std::hex << temp << endl;
in this case:
1010000
This version number may not be in any way related to the user-visible version number the DLL (i.e. the one you see in the Windows Properties panel).
digog
8th November 2010, 21:58
Thanks, problem resolved. the code now is:
DWORD temp = MPUSBGetDLLVersion();
int aux1 = HIWORD(temp)>>8;
int aux2 = HIWORD(temp) & 0xFF;
int aux3 = LOWORD(temp)>>8;
int aux4 = LOWORD(temp) & 0xFF;
lineEdit2->setText( tr("MPUSBAPI Version:%1.%2.%3.%4").arg(QString::number(aux1,10))
.arg(QString::number(aux2,10)).arg(QString::number (aux3,10))
.arg(QString::number(aux4,10)));
And it displays MPUSBAPI Version:1.1.0.0
I was using a new version of the dll and didn't know before.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.