Results 1 to 2 of 2

Thread: winId() and UI events

  1. #1
    Join Date
    Jan 2013
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Unhappy winId() and UI events

    Hi all,

    I have the strange behavior when using QWidget::winId() method (on Windows).
    When I used Qt 4.8.4 everything was OK.
    But in 5.0.0 and 5.0.1 if I call winId() for one of the child widgets, the first widget in the hierarchy stops responding to UI events.

    I created the simple example:

    Qt Code:
    1. #include <QtWidgets/QApplication>
    2. #include <QtWidgets/QDialog>
    3. #include <QPushButton>
    4.  
    5. QDialog *dialog1;
    6. QDialog *dialog2;
    7.  
    8. QPushButton *button1;
    9. QPushButton *button2;
    10.  
    11. void Button2_clicked()
    12. {
    13. WId hwnd = button2->winId();
    14. }
    15.  
    16. void Button1_clicked()
    17. {
    18. dialog2 = new QDialog(dialog1);
    19. dialog2->resize(120, 30);
    20.  
    21. button2 = new QPushButton("Button2", dialog2);
    22. QObject::connect(button2, &QPushButton::clicked, Button2_clicked);
    23.  
    24. dialog2->exec();
    25. delete dialog2;
    26. }
    27.  
    28. int main(int argc, char *argv[])
    29. {
    30. QApplication a(argc, argv);
    31.  
    32. dialog1 = new QDialog;
    33. dialog1->resize(200, 50);
    34.  
    35. button1 = new QPushButton("Button1", dialog1);
    36. QObject::connect(button1, &QPushButton::clicked, Button1_clicked);
    37.  
    38. dialog1->exec();
    39. delete dialog1;
    40.  
    41. return 0;
    42. }
    To copy to clipboard, switch view to plain text mode 

    Scenario 1:

    1. Press "button1" in first dialog - second dialog appears.
    2. Close second dialog.
    3. Press "button1" again - it works.

    Scenario 2:

    1. Press "button1" in first dialog - second dialog appears.
    2. Press "button2" in first dialog - called void Button2_clicked() { WId hwnd = button2->winId(); }
    2. Close second dialog.
    3. Press "button1" again - don't pressed.

    I have the same behavior if use QMainWindow and QWidget instead of QDialogs.

    Windows 7 x64 Pro
    Qt 5.0.1 (5.0.0 - the same)
    Visual Studio 2010 SP1
    Qt5 Visual Studio Add-in

  2. #2
    Join Date
    Jan 2013
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: winId() and UI events

    So, nobody have any ideas? Or nobody can reproduce this?
    It's a pity, because I can not use winId() because of this...

Similar Threads

  1. About FramelessWindowHint and winId
    By Wong in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2011, 08:19
  2. QWidget::winId() can not get the right window handle
    By ponponfish in forum Qt Programming
    Replies: 2
    Last Post: 17th May 2011, 06:45
  3. winId() crashed
    By nedivi in forum Qt Programming
    Replies: 1
    Last Post: 6th March 2011, 23:03
  4. Can't get Widget from WinID()
    By abbapatris in forum Qt Programming
    Replies: 3
    Last Post: 9th July 2008, 17:25
  5. Winid issue with Qt
    By Pragya in forum Qt Programming
    Replies: 6
    Last Post: 7th June 2007, 13:10

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.