Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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.

    mainwindow.h:

     class MainWindow : public QMainWindow 
     {
         Q_OBJECT
    
         public:
            explicit MainWindow(QWidget *parent = 0);
            ~MainWindow();
    
         private:
             Ui::MainWindow * _ui = nullptr;
             QDockWidget * _dock = nullptr;
    };
    

    mainwindow.cpp:

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

    widgetfordock.h:

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

    widgetfordock.cpp:

    WidgetForDock::WidgetForDock(const QString &name, QWidget *parent) :
        QWidget(parent),
        _ui(new Ui::WidgetForDock)
    {
        _ui->setupUi(this);
        _ui->name->setText(name);
    
        _action1 = new QAction(tr("Show child dock 1"), this);
        _action1->setCheckable(true);
    
        _action2 = new QAction(tr("Show child dock 2"), this);
        _action2->setCheckable(true);
    
        _action3 = new QAction(tr("Show child dock 3"), this);
        _action3->setCheckable(true);
    
        _dock1 = new QDockWidget("Child Dock 1", parent);
        _dock1->setFloating(true);
        _dock1->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        _dock1->setVisible(false);
    
        _dock2 = new QDockWidget("Child Dock 2", parent);
        _dock2->setFloating(true);
        _dock2->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        _dock2->setVisible(false);
    
        _dock3 = new QDockWidget("Child Dock 3", parent);
        _dock3->setFloating(true);
        _dock3->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        _dock3->setVisible(false);
    
    
        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)));
    }
    
    
    WidgetForDock::~WidgetForDock()
    {
        delete _ui;
    }
    
    void WidgetForDock::showMenu()
    {
        QMenu * menu = new QMenu(this);
    
        menu->addAction(_action1);
        menu->addAction(_action2);
        menu->addAction(_action3);
    
        QPoint pos = mapToGlobal(_ui->menu->pos());
    
        pos.ry() += _ui->menu->size().height();
    
        menu->exec(pos);
    }
    

    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