I have an Widget class as a QtPlugin. In my main application i want to load this widget and add to menubar as toggledaction, so that later if i close the widget i can open it via the Menu bar. How can this be achieved.

As this is not a docketwidget i cannot use the following:

Qt Code:
  1. ui->menuPlugins->addAction(dockedWidget->toggleViewAction());
To copy to clipboard, switch view to plain text mode 

I have tried something like this:

Qt Code:
  1. void MainWindow::addToPluginsMenu(QWidget *const widget) {
  2. ui->menuPlugins->setEnabled(true);
  3. QWidgetAction *ac = new QWidgetAction(this);
  4. ui->menuPlugins->addAction(ac);
  5. }
To copy to clipboard, switch view to plain text mode 
An action is added but it is empty and cannot be toggled. Could anyone provide me a solution?

Thank you