The function window()->windowHandle(); always returns nullptr in my custom widget.
-
I want to obtain the QWindow handler within the constructor of my custom widget, but it always returns a null pointer.
class MyWidget : public QWidget { Q_OBJECT public: MyWidget() { QWindow *win = window()->windowHandle(); std::println("win equals nullptr: {}", win == nullptr); // prints true } };
How can I get the QWindow handler ?
-
I want to obtain the QWindow handler within the constructor of my custom widget, but it always returns a null pointer.
class MyWidget : public QWidget { Q_OBJECT public: MyWidget() { QWindow *win = window()->windowHandle(); std::println("win equals nullptr: {}", win == nullptr); // prints true } };
How can I get the QWindow handler ?
-
I want to obtain the QWindow handler within the constructor of my custom widget, but it always returns a null pointer.
class MyWidget : public QWidget { Q_OBJECT public: MyWidget() { QWindow *win = window()->windowHandle(); std::println("win equals nullptr: {}", win == nullptr); // prints true } };
How can I get the QWindow handler ?
-
void MyWidget::showEvent(QShowEvent *event) { if(this->win == nullptr) { this->win = window()->windowHandle(); } QWidget::showEvent(event); }
Apart from this way, I wonder if there are any other more elegant solutions?
-