Results 1 to 7 of 7

Thread: Retrieving QString from TCHAR

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Retrieving QString from TCHAR

    Quote Originally Posted by GTBuilder View Post
    Using the NativeWindow class prints a blank line.
    Then perhaps you'll have to pass true as initializeWindow parameter. I don't have access to a Windows machine atm so I cannot test myself, sorry.
    J-P Nurmi

  2. #2
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Retrieving QString from TCHAR

    I've solved the problem. The following code gives me what I want.

    Qt Code:
    1. #include <QWidget>
    2. #include <windows.h>
    3.  
    4. HWND hChild;
    5. PTSTR pTitle;
    6. QString str;
    7. char cTitle[8];
    8.  
    9. hChild = GetForegroundWindow();
    10. pTitle = (PTSTR) malloc ( 8 * sizeof (TCHAR)) ;
    11. GetWindowText( hChild, pTitle, 8);
    12.  
    13.  
    14. for( int i=0; i<7; i++)
    15. {
    16. cTitle[i] = static_cast<char>( *(pTitle + i));
    17. str.append( cTitle[i]);
    18. }
    19.  
    20. labelTitle->setText( str);
    To copy to clipboard, switch view to plain text mode 

    Not sure how universal such an approach is, but my target platform is specific, so not a problem.

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving QString from TCHAR

    @GTBuilder: Your approach is wrong as it only works for ascii window titles.

Similar Threads

  1. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  2. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  3. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55
  4. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10
  5. [SOLVED] Widget plugin ... how to ?
    By yellowmat in forum Newbie
    Replies: 10
    Last Post: 29th January 2006, 20:41

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.