PDA

View Full Version : winId() and UI events



allexz
17th February 2013, 20:24
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:


#include <QtWidgets/QApplication>
#include <QtWidgets/QDialog>
#include <QPushButton>

QDialog *dialog1;
QDialog *dialog2;

QPushButton *button1;
QPushButton *button2;

void Button2_clicked()
{
WId hwnd = button2->winId();
}

void Button1_clicked()
{
dialog2 = new QDialog(dialog1);
dialog2->resize(120, 30);

button2 = new QPushButton("Button2", dialog2);
QObject::connect(button2, &QPushButton::clicked, Button2_clicked);

dialog2->exec();
delete dialog2;
}

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

dialog1 = new QDialog;
dialog1->resize(200, 50);

button1 = new QPushButton("Button1", dialog1);
QObject::connect(button1, &QPushButton::clicked, Button1_clicked);

dialog1->exec();
delete dialog1;

return 0;
}


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

allexz
19th February 2013, 01:05
So, nobody have any ideas? Or nobody can reproduce this?
It's a pity, because I can not use winId() because of this...