Important: Please read the Qt Code of Conduct -

QDialog window disappears

  • Hi,

    In my main window GUI I'm using the following code to show a popup window without creating a icon on the taskbar:

    QDialog popup;
    QMainWindow mainWindow(&popup);;

    somehow it appears for half a second and then disappear.

    anyone can help?

  • Sure. You're making a common mistake. As soon as the variables you declared (both popup and mainWindow) go out of scope, that is, your function reaches the closing } on line 5, their destructor gets called.

    You'll need to allocate objects that need to live beyond the lifetime of your function on the heap instead. Use the keyword "new" for that.

  • uff,
    of course you're right.

    i feel embarrassed now :P

Log in to reply