Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need something like a finished-signal from QWidget

I'm searching for something like the finished-signal from QDialog, only for QWidget. The reason is, I disable my toolbar once the widget pops up (which isn't a problem at all) and I want the toolbar to be enabled again, once the widget is closed.

I also can't override the close-Event of that widget, because then we would have GUI-code in business-classes.

like image 636
LarissaGodzilla Avatar asked Oct 28 '11 10:10

LarissaGodzilla


People also ask

How do you emit signals in Qt?

In Qt, we have an alternative to the callback technique: We use signals and slots. A signal is emitted when a particular event occurs. Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them. A slot is a function that is called in response to a particular signal.

Can we connect signal to signal in Qt?

This ensures that truly independent components can be created with Qt. You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need. It is even possible to connect a signal directly to another signal.

How do I turn off QWidget?

Detailed Description. Close events are sent to widgets that the user wants to close, usually by choosing "Close" from the window menu, or by clicking the X title bar button. They are also sent when you call QWidget::close() to close a widget programmatically.

How do Qt signals work?

The Qt signals/slots and property system are based on the ability to introspect the objects at runtime. Introspection means being able to list the methods and properties of an object and have all kinds of information about them such as the type of their arguments.


1 Answers

You can set the widget to be deleted on close, and then listen to its destroyed signal:

widget->setAttribute( Qt::WA_DeleteOnClose );
connect( widget, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed(QObject*)) );

That only works if you're not interested in the widget contents though. At the point destroyed() is emitted, the widget isn't a QWidget anymore, just a QObject (as destroyed() is emitted from ~QObject), so you can't cast the argument QObject* to QWidget anymore.

A simple alternative might be to wrap your widget with a QDialog.

like image 78
Frank Osterfeld Avatar answered Oct 04 '22 11:10

Frank Osterfeld