Can I have a window that uses Qt::WA_DeleteOnClose and has a taskbar button at the same time?
-
The question might sound weird, but bear with me.
- In order for Qt::WA_DeleteOnClose to work the window (be it
QWidget
orQMainWindow
; happens to be aQMainWindow
in my case) must have a non-null parent. - In order for a window to have a taskbar button, at least on Windows, it must have a nullptr parent.
Quite a dilemma. Looks like I must implement deletion on close manually, but I would prefer a standard solution.
- In order for Qt::WA_DeleteOnClose to work the window (be it
-
@Violet-Giraffe said:
In order for Qt::WA_DeleteOnClose to work the window must have a non-null parent.
Where did you get that idea from? That's not true at all.
-
From my experiments. I'm certain of it, triple-checked.
-
I'm afraid you're gonna have to try it the fourth time then ;)
I suggest the following example for that:#include <QApplication> #include <QWidget> #include <QDebug> struct Widget : public QWidget { ~Widget() { qDebug() << "deleted!"; } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); auto w = new Widget(); w->setAttribute(Qt::WA_DeleteOnClose); w->show(); return a.exec(); }
Widget obviously has no parent and the output is "deleted!", as expected.
So you're doing something wrong. What problem are you trying to solve?
-
Yep, this works. But my window still doesn't. Weird.
-
If you provide us with that window's code we might be able to pinpoint the problem.