Results 1 to 8 of 8

Thread: DWORD to QSTRING

  1. #1
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default DWORD to QSTRING

    Hello,

    Has anyone an idea on how to convert a DWORD to a QSTRING to display in a lineEdit?

    Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: DWORD to QSTRING

    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?

  3. #3
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DWORD to QSTRING

    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:
    Qt Code:
    1. DWORD temp = MPUSBGetDLLVersion();
    2. lineEdit2->setText( tr("MPUSBAPI Version:%1.%2").arg(QString::number( HIWORD(temp),10))
    3. .arg(QString::number(LOWORD(temp),10)));
    To copy to clipboard, switch view to plain text mode 

    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?
    Last edited by digog; 8th November 2010 at 05:17.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DWORD to QSTRING

    Looks like you need to shift the higher word to the right (257 = 256+1).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DWORD to QSTRING

    Quote Originally Posted by wysota View Post
    Looks like you need to shift the higher word to the right (257 = 256+1).
    How can I do it?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: DWORD to QSTRING

    Quote Originally Posted by digog View Post
    How can I do it?
    Most likely using the C++ binary shift operator.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: DWORD to QSTRING

    From a quick Google it seems the version number is typically output in hexadecimal:
    http://www.microchip.com/forums/m346499-print.aspx
    Qt Code:
    1. temp = MPUSBGetDLLVersion();
    2. cout << "DLL Version => " << std::hex << temp << endl;
    To copy to clipboard, switch view to plain text mode 
    in this case:
    Qt Code:
    1. 1010000
    To copy to clipboard, switch view to plain text mode 

    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).
    Last edited by ChrisW67; 9th November 2010 at 02:06.

  8. #8
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DWORD to QSTRING

    Thanks, problem resolved. the code now is:

    Qt Code:
    1. DWORD temp = MPUSBGetDLLVersion();
    2.  
    3. int aux1 = HIWORD(temp)>>8;
    4. int aux2 = HIWORD(temp) & 0xFF;
    5. int aux3 = LOWORD(temp)>>8;
    6. int aux4 = LOWORD(temp) & 0xFF;
    7.  
    8. lineEdit2->setText( tr("MPUSBAPI Version:%1.%2.%3.%4").arg(QString::number(aux1,10))
    9. .arg(QString::number(aux2,10)).arg(QString::number(aux3,10))
    10. .arg(QString::number(aux4,10)));
    To copy to clipboard, switch view to plain text mode 

    And it displays MPUSBAPI Version:1.1.0.0
    I was using a new version of the dll and didn't know before.

Similar Threads

  1. #include <mmsystem.h> and DWORD ?
    By nthung in forum Qt Programming
    Replies: 3
    Last Post: 28th May 2010, 13:46
  2. With QString create a QString&
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 21st April 2010, 22:05
  3. Replies: 4
    Last Post: 1st February 2010, 14:21
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. how to copy part of QString to anothe QString
    By nass in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2007, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.