I have a program which instantiates and uses another class (subclass of Qwidget) . When I closed the widget, program does not terminate, how can I also terminate main function?
I have a program which instantiates and uses another class (subclass of Qwidget) . When I closed the widget, program does not terminate, how can I also terminate main function?
In main program, I have a infinite loop, and I need to stop infinite loop when widget is closed by user.
But, how will understand that widget is closed? I put qApp->quit(); to destructor of QT class, but it didn't work.
usually this line
is added in main.cpp or you can use QApplication::setQuitOnLastWindowClosedQt Code:
... ...To copy to clipboard, switch view to plain text mode
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
Should I rewrite quit() slot?
why? take a look at QCoreApplication::quit, moreover, you can't do this since this method is not virtual.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
no just use the connect spirit suggest you ..
quit() is a static slot
void QCoreApplication::quit () [static slot]
"Behind every great fortune lies a crime" - Balzac
no need of rewrite.. its like u want to rewrite exit(0)
Then I guess I should try another thing, because it does not work, after widget is closed, my program keeps working.
so, provide a compilable example which reproduces the problem to us.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
here main function and function which contains infinite loop
Qt Code:
int main(int argc, char *argv[]) { //GUI part rovkonInterface w; //subclass of Qwidget w.show(); userInterface=&w; // start the receive thread ReceiveThread(); return a.exec(); } void ReceiveThread() { rovkonInterface *w=((rovkonInterface *)userInterface); while ( lMustQuit == 0 ) { a->processEvents(); } }To copy to clipboard, switch view to plain text mode
if you use another thread then tyr to add one more connection in main.cpp
Qt Code:
... ...To copy to clipboard, switch view to plain text mode
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
btw, you can use qApp insted of this QApplication *a=((QApplication *)qtApplication);
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
Thanks for the "qApp" tip.
and sorry for the bad names I gave to functions. Actually there is no other thread, there is just a function with infinite loop and I added "a->processEvents();" in order to prevent freezing in widgets as you can see in code above.
Simply ReceiveThread() continues to run infinite loop when widget is closed, I need to stop this infinite loop.
Thanks anyway
in rovkonInterface class
is it a QDialog or QWidget ..
if QDialog we can receive
void QDialog::rejected ()
with that rejected call we can quit our application like
Qt Code:
To copy to clipboard, switch view to plain text mode
"Behind every great fortune lies a crime" - Balzac
It is Qwidget.
Qt Code:
rovkonInterface w; //subclass of QwidgetTo copy to clipboard, switch view to plain text mode
so u try emit your custom signal on rovkonInterface closeEvent()
reimplement closeEvent() in rovkonInterface() class
emit widgetClosed() // your custom signal
and
QObject::connect( w, SIGNAL(widgetClosed()), qApp, SLOT(quit()) );
"Behind every great fortune lies a crime" - Balzac
Bookmarks