Now, where would I have gotten the idea that the function works...
#include <QApplication>
#include <QWidget>
#include <QWindow>
#include <QTimer>
#include <QDebug>
{
Q_OBJECT
public:
qDebug() << "Start constructor" << windowHandle();
setWindowTitle("A Cool Title"); // this triggers OS window creation
qDebug() << "End constructor" << windowHandle();
QTimer::singleShot(0,
this,
SLOT(report
()));
}
public slots:
void report() {
qDebug() << "After show()" << windowHandle();
if (windowHandle())
qDebug() << "QWindow::title()" << windowHandle()->title();
}
protected:
qDebug() << "In paintEvent()" << windowHandle();
}
};
int main(int argc, char **argv)
{
Widget w;
w.show();
return app.exec();
}
#include "main.moc"
#include <QApplication>
#include <QWidget>
#include <QWindow>
#include <QTimer>
#include <QDebug>
class Widget: public QWidget
{
Q_OBJECT
public:
Widget(QWidget *p = 0): QWidget(p) {
qDebug() << "Start constructor" << windowHandle();
setWindowTitle("A Cool Title"); // this triggers OS window creation
qDebug() << "End constructor" << windowHandle();
QTimer::singleShot(0, this, SLOT(report()));
}
public slots:
void report() {
qDebug() << "After show()" << windowHandle();
if (windowHandle())
qDebug() << "QWindow::title()" << windowHandle()->title();
}
protected:
void paintEvent(QPaintEvent *event) {
qDebug() << "In paintEvent()" << windowHandle();
QWidget::paintEvent(event);
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Widget w;
w.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
On Linux
End constructor QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
After show() QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
QWindow::title() "A Cool Title"
In paintEvent() QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
In paintEvent() QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
Start constructor QObject(0x0)
End constructor QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
After show() QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
QWindow::title() "A Cool Title"
In paintEvent() QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
In paintEvent() QWidgetWindow(0xe902d0, name = "WidgetClassWindow")
To copy to clipboard, switch view to plain text mode
On Windows 7 using Qt 5.0.1 MingW build:
Z:\uu>qmake -v
QMake version 3.0
Using Qt version 5.0.1 in C:\Qt\Qt5.0.1\5.0.1\mingw47_32\lib
End constructor QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
After show() QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
QWindow::title() "A Cool Title"
In paintEvent() QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
In paintEvent() QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
Z:\uu>qmake -v
QMake version 3.0
Using Qt version 5.0.1 in C:\Qt\Qt5.0.1\5.0.1\mingw47_32\lib
Start constructor QObject(0x0)
End constructor QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
After show() QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
QWindow::title() "A Cool Title"
In paintEvent() QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
In paintEvent() QWidgetWindow(0xa1ec28, name = "WidgetClassWindow")
To copy to clipboard, switch view to plain text mode
Bookmarks