PDA

View Full Version : QWidgetAction doesn't allow app to quit



manatttta
20th April 2017, 16:26
I created a menu in my QMainWindow derived class, and added a QWidget to it via QWidgetAction. Now my app does not close and stays in infinite loop when I try to close it. Any hints on why this happens?

Here's the code:

MainWindow* parent = ...;
auto menu = parent->menuBar()->addMenu("Menu");
auto action = new QWidgetAction(menu);
auto widget = new QLabel("Lol");
action->setDefaultWidget(widget);
menu->addAction(action);


This happens under OSX Sierra, Qt 5.8

d_stranz
20th April 2017, 23:16
Considering you haven't told us anything about where this code actually gets executed, and what happens inside the "..." of the first line, it's pretty much impossible to say what the error is.

My guess is that in the first line you are creating a new MainWindow instance (and different from the one you create in main()), so you end up with an app that has multiple instances of MainWindow running at the same time.

manatttta
21st April 2017, 11:05
I simply created a QMainWindow application on QtCreator and ran it with that code for creating the menu with the widget.

On Ubuntu Linux, nothing is rendered. Under OSX, it creates an infinite loop when I try to close the app

d_stranz
21st April 2017, 21:36
I'll say it again:


Considering you haven't told us anything about where this code actually gets executed, and what happens inside the "..." of the first line, it's pretty much impossible to say what the error is.