Results 1 to 4 of 4

Thread: Converting from Qt's WId to Windows HWND?

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Converting from Qt's WId to Windows HWND?

    What's the proper method of converting the result from QWidget::winID(), to a HWND__*?

    QWidget's WId is defined as:
    Qt Code:
    1. typedef QIntegerForSizeof<void*>::Unsigned quintptr;
    2. typedef QT_PREPEND_NAMESPACE(quintptr) WId;
    To copy to clipboard, switch view to plain text mode 

    Currently, I'm just doing:
    Qt Code:
    1. HWND handle = (HWND)this->windID();
    To copy to clipboard, switch view to plain text mode 

    Is that the correct method?

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

    Default Re: Converting from Qt's WId to Windows HWND?

    Does it work?
    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.


  3. #3
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Converting from Qt's WId to Windows HWND?

    It appears to, but I've programmed long enough to know that things that "appear" to work are not always correct. Who knows? Maybe my cast truncates the int in some way, and though it happens coincidentally to work on my machine, it may completely fail on someone else's. =)

    I just switched from Qt 4.8 to Qt 5.0, and am dealing with a number of minor problems in my not-so-simple application, so I'm chipping away piece by piece to get everything working again properly.

    One of the possible problem sources is getting a HWND for a child-widget. If I am only guessing that "HWND handle = (HWND)this->windID();" is the right solution, I want to get it confirmed as correct to eliminate it as a problem suspect. I read the documentation for the winID() function, and I walked through a few of the related Qt headers, but I don't know for sure if this is the proper usage.

    Do you or anyone know how it works under the hood, and can confirm or deny that this is the right way to get a HWND? A sentence or so could also be added to the documentation.

    In Qt 4.8 it worked without needing to explitily cast. In Qt 5, I think the function name changed, and the return result requires a cast. The window is a child widget of another window.

    Should I be using effectiveWinID()? I'm rather put off by the remark: "Note: We recommend that you do not store this value as it is likely to change at run-time."

    I have a main window, with child widgets with Qt-related buttons and things. In the center of the main window is a child widget that is drawn by a different API (SFML). I want to give this non-Qt API the central child widget's HWND so it can draw on it properly. Am I supposed to be watching for QEvent::WinIdChange? How to I process that on Qt's side? Am I supposed to use effectiveWInID() or just winID(), and what is the official Qt-approved way to convert it to HWND?

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Converting from Qt's WId to Windows HWND?

    should always prefer c++ casts over c casts.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Get HWND of QGLWidget
    By pl01 in forum Newbie
    Replies: 2
    Last Post: 19th December 2010, 21:18
  2. Converting existing Windows app
    By GrahamLabdon in forum Qt Programming
    Replies: 1
    Last Post: 22nd March 2010, 09:43
  3. converting Windows dialog resources to ui
    By Thor28 in forum Qt Tools
    Replies: 3
    Last Post: 21st April 2008, 15:13
  4. Convert Windows "HWND" to QWidget* pointer?
    By gerome69 in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2006, 13:03
  5. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 01:00

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.