Important: Please read the Qt Code of Conduct -

External WM_DESTROY received for QWidgetWindow by docking QDockWidget

  • Hi. I have QDockWidget (main) and in this dock I have 3 child docks. MainWindow is parent for main dock and main dock is parent for his 3 child docks. I open main dock, next I open his 3 child docks. Main dock is above MainWindow and child docks is above main dock - this is OK. Next I am docking main dock into main window and first child dock is showing (its ok), but lost his parent and I cann first child under MainWindow (this is bad). 2 and 3 child docks is hiding (this is bad) and I cannot again show this two docks.


     class MainWindow : public QMainWindow 
            explicit MainWindow(QWidget *parent = 0);
             Ui::MainWindow * _ui = nullptr;
             QDockWidget * _dock = nullptr;


    MainWindow::MainWindow(QWidget *parent) :
        _ui(new Ui::MainWindow)
     _dock = new QDockWidget("Main Dock", this);
     _dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     QWidget * widgetForDock = new WidgetForDock("Main Dock ...", _dock);
     QObject::connect(_ui->showDock, SIGNAL(clicked(bool)), _dock, SLOT(setVisible(bool)));
     QObject::connect(_dock, SIGNAL(visibilityChanged(bool)), _ui->showDock, SLOT(setChecked(bool)));
        delete _ui;


    class WidgetForDock : public QWidget
        WidgetForDock(const QString &name, QWidget *parent = 0);
    private slots:
        void showMenu();
        Ui::WidgetForDock * _ui = nullptr;
        QAction * _action1 = nullptr;
        QAction * _action2 = nullptr;
        QAction * _action3 = nullptr;
        QDockWidget * _dock1 = nullptr;
        QDockWidget * _dock2 = nullptr;
        QDockWidget * _dock3 = nullptr;


    WidgetForDock::WidgetForDock(const QString &name, QWidget *parent) :
        _ui(new Ui::WidgetForDock)
        _action1 = new QAction(tr("Show child dock 1"), this);
        _action2 = new QAction(tr("Show child dock 2"), this);
        _action3 = new QAction(tr("Show child dock 3"), this);
        _dock1 = new QDockWidget("Child Dock 1", parent);
        _dock1->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        _dock2 = new QDockWidget("Child Dock 2", parent);
        _dock2->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        _dock3 = new QDockWidget("Child Dock 3", parent);
        _dock3->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        QObject::connect(_ui->menu, SIGNAL(clicked(bool)), SLOT(showMenu()));
        QObject::connect(_action1, SIGNAL(triggered(bool)), _dock1, SLOT(setVisible(bool)));
        QObject::connect(_dock1, SIGNAL(visibilityChanged(bool)), _action1, SLOT(setChecked(bool)));
        QObject::connect(_action2, SIGNAL(triggered(bool)), _dock2, SLOT(setVisible(bool)));
        QObject::connect(_dock2, SIGNAL(visibilityChanged(bool)), _action2, SLOT(setChecked(bool)));
        QObject::connect(_action3, SIGNAL(triggered(bool)), _dock3, SLOT(setVisible(bool)));
        QObject::connect(_dock3, SIGNAL(visibilityChanged(bool)), _action3, SLOT(setChecked(bool)));
        delete _ui;
    void WidgetForDock::showMenu()
        QMenu * menu = new QMenu(this);
        QPoint pos = mapToGlobal(_ui->menu->pos());
        pos.ry() += _ui->menu->size().height();

    Would someone know what to do wrong? Thanks

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Why do you have dock widgets within a widget that you set in a docker widget ?

  • It is current stat in company application. This app is developing a few years and this state has been a gradual development. I try change 3 child docks for QDialog, but after docking main dock, qdialog is hiding (with message in console "External WM_DESTROY received for QWidgetWindow(0x234cd3b0, name="QDialogClassWindow") , parent: QWindow(0x0) , transient parent: QWidgetWindow(0x234683c8, name="QDockWidgetClassWindow")") and I cannot again show this QDialog.

  • Lifetime Qt Champion

    What about not giving them a parent and put them in widgets with layout ?

Log in to reply