Hello all,
I'm new to Qt (4.8.1 for Desktop + MSVC2010) and also just starting to get a handle on C++, and I'm trying to interact with a 3rd party driver DLL that sends Events to a HWDN (which I attempt to set via MainWindow::effectiveWinId() ). This has been working, though apparently only by chance, as inside my MainWindow, before setting said HWND, I called created a QMessageBox.
My MainWindow is a regular UI-Designer subclassed QMainWindow:
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
virtual bool winEvent( MSG* message, long* result );
~MainWindow();
private:
Ui::MainWindow *ui;
....
void installmessages();
private slots:
void on_freezeButton_clicked();
};
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
virtual bool winEvent( MSG* message, long* result );
~MainWindow();
private:
Ui::MainWindow *ui;
....
void installmessages();
private slots:
void on_freezeButton_clicked();
};
To copy to clipboard, switch view to plain text mode
The code in MainWindow::installmessages();
qDebug() << "before";
qDebug() << MainWindow::effectiveWinId() ;
// *
qDebug() << "messagebox";
tr("Messagebox title"),
tr("WinID %1").arg( (long) MainWindow::effectiveWinId() )
);
// */
qDebug() << "after";
qDebug() << MainWindow::effectiveWinId() ;
....
[call to proprietary library with MainWindow::effectiveWinId() as parameter]
qDebug() << "before";
qDebug() << MainWindow::effectiveWinId() ;
// *
qDebug() << "messagebox";
QMessageBox::information( this,
tr("Messagebox title"),
tr("WinID %1").arg( (long) MainWindow::effectiveWinId() )
);
// */
qDebug() << "after";
qDebug() << MainWindow::effectiveWinId() ;
....
[call to proprietary library with MainWindow::effectiveWinId() as parameter]
To copy to clipboard, switch view to plain text mode
results in this output
before
0x0
messagebox [the output is "WinID 0"]
after
0x17046a
before
0x0
messagebox [the output is "WinID 0"]
after
0x17046a
To copy to clipboard, switch view to plain text mode
So with message box, my program works since I get a valid ID and thus receive messages.
Why is the WinID valid only when the MessageBox is run?
Bookmarks