Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I quit a qt console application? Are there criterions for the QApplication::quit() slot to work?
    primarykey
    data
    text
    <p>I have a weird qt problem: My application doesn't quit in some configurations. </p> <p>The idea is to have a program, which can be started as a program with a GUI (through <code>myWindow</code>) or as a pure console application (controlled via <code>myConsole</code>, which runs its own loop in its thread to record keyboard inputs). Either way quitting is done by calling the <code>myObject</code> slot <code>quitMyObject</code>, which in turn cleans up some objects and emits the signal <code>signalQuitapplication</code>, which is connected to the <code>QApplication</code> (<code>app</code>) <code>quit</code> slot.</p> <p>Unfortunately the application only quits when the the window is enabled and the quit command is entered in the console (although the <code>slotQuitMyObject</code> of <code>myObject</code> is always called). So I wonder what criterions Qt has to actually quit the main event loop and exit the program.</p> <p>The code looks like this:</p> <pre><code>int main(int argc, char *argv[]) { bool enableWindow = false; QApplication app(argc, argv, enableWindow); MyUiAbstract* myConsole = new ConsoleUi(); // ConsoleUi inherits from MyUiAbstract, which inherits from QThread MyWindow* myWindow = NULL; // MyWindow inherits from QMainWindow if(enableWindow) { myWindow = new MyWindow(); myWindow-&gt;show(); } MyObject* myObject = new MyObject(myConsole, myWindow, ...); QObject::connect(myObject, SIGNAL(signalQuitQApplication()), &amp;app, SLOT(quit()), Qt::QueuedConnection); QObject::connect(myConsole, SIGNAL(signalQuitMyObject()), myObject, SLOT(slotQuitMyObject()), Qt::QueuedConnection); QObject::connect(myWindow, SIGNAL(signalQuitMyObject()), myObject, SLOT(slotQuitMyObject()), Qt::QueuedConnection); QObject::connect(myWindow, SIGNAL(signalQuitConsoleUI()), myConsole, SLOT(slotQuitMyUi()), Qt::QueuedConnection); return app.exec(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload