Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can I have a window that uses Qt::WA_DeleteOnClose and has a taskbar button at the same time?
QtWS25 Last Chance

Can I have a window that uses Qt::WA_DeleteOnClose and has a taskbar button at the same time?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    The question might sound weird, but bear with me.

    1. In order for Qt::WA_DeleteOnClose to work the window (be it QWidget or QMainWindow; happens to be a QMainWindow in my case) must have a non-null parent.
    2. 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.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        From my experiments. I'm certain of it, triple-checked.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #4

          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?

          1 Reply Last reply
          1
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by
            #5

            Yep, this works. But my window still doesn't. Weird.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              If you provide us with that window's code we might be able to pinpoint the problem.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved