Executing QDialog from a class inherited from QObject
Radim last edited by Radim
I have an
Programclass, which inherits from
Engine, which inherits from
Engineclass do some processing. The processing is started using a
bool run()method implemented in the
Programclass. It returns true if it has been started or false if it failed. The error string can be read via
QString errorString()method. When the processing is finished, the class sends a signal.
Now I need to ask the user in the
run()method whether to ignore some error and continue or quit. I know that I cannot inherit the
Programclass is constructed using
QWidgetparent object. Is it a good idea to cast
thisobject in the
run()method to initialize a
QDialog(so it appears in the middle of the main window)?
QDialog *dialog = new QDialog(qobject_cast<QWidget*>(this));
Or should I use a different approach to ask a user from within a class inherited from
Yes, you should use a different approach. The first thing to think about is: does it really make sense to have the dialog handling in that object ? Should it be the responsibility of e.g. the main window ? Like Program sending a signal for more inputs and main window get them before sending them to Program. Then the second thing is: will Program be used in a different thread ? If so, then you can't run GUI related stuff in a thread that is not the main thread a.k.a the GUI thread.