I encountered this error while writing my own application. I have a QDockWidget with parameters for my application. Using Qt Creator, I created a menu with a QAction actionMenu that could be checked. Then I hooked up QDockWidget and QAction as follows:
QObject::connect(ui->dockWidget, SIGNAL(visibilityChanged(bool)), ui->actionMenu, SLOT(setChecked(bool))); QObject::connect(ui->actionMenu, SIGNAL(toggled(bool)), ui->dockWidget, SLOT(setVisible(bool)));
The connection order does not matter. And then, when I minimized the application with QDockWidget visibility, after I restored it, QDockWidget was closed, and actionMenu was not marked.
There are actually two solutions. First, I work to use SIGNAL (triggered (bool)) instead of SIGNAL (toggled (bool)):
QObject::connect(ui->dockWidget, SIGNAL(visibilityChanged(bool)), ui->actionMenu, SLOT(setChecked(bool))); QObject::connect(ui->actionMenu, SIGNAL(triggered(bool)), ui->dockWidget, SLOT(setVisible(bool)));
The second solution uses an action that you can get from QDockWidget:
// Retrieve action from QDockWidget. QAction *action = ui->dockWidget->toggleViewAction(); // Adjust any parameter you want. action->setText(QString("&Menu")); action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); action->setStatusTip(QString("Press to show/hide menu widget.")); action->setChecked(true); // Install action in the menu. ui->menuOptions->addAction(action);
I know for sure that SIGNAL (toggled (bool)) causes QDockWidget to close in my application.
source share