Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't close GUI program
    primarykey
    data
    text
    <p>In my project, I have a dialog that displays that has two buttons. If someone presses "Yes" then I want the program to close. But I can't seem to get it to work.</p> <p>I have tried all of these.</p> <pre><code>qApp-&gt;exit(); qApp-&gt;quit(); QApplication::exit(); QApplication::quit(); QCoreApplication::exit(); QCoreApplication::quit(); </code></pre> <p>And none of these close the program. I tried moving them into my main.cpp, I tried making a second function just for closing, and nothing works.</p> <p>Would it have anything to do with my event loop earlier that checks for updates? If so, I will post it.</p> <p>EDIT:</p> <p>Here is my main.cpp and the function where I want my program to close:</p> <pre><code>#include "mainwindow.h" #include &lt;QApplication&gt; int main(int argc, char *argv[]) { Q_INIT_RESOURCE(icons); QApplication a(argc, argv); MainWindow w; w.show(); w.checkVersion(); return a.exec(); } </code></pre> <p>Function:</p> <pre><code>void MainWindow::checkVersion() { if((version != "1.0.0") &amp;&amp; (version != ""))//version is a string that is filled when the mainwindow first opens. { QMessageBox::StandardButton reply; reply = QMessageBox::question(this, "Update", "Version " + version + " is now available. Would you like to update now?\n\nOr visit http://www.youtube.com/oPryzeLP to download manually.", QMessageBox::Yes | QMessageBox::No); if(reply == QMessageBox::Yes) { } QApplication::exit();//moved out of reply just to test closing } } </code></pre> <p>This is the function that contains the event loop:</p> <pre><code>void MainWindow::downloadFile(const QString &amp;url, const QString &amp;aPathInClient) { QNetworkAccessManager* m_NetworkMngr = new QNetworkAccessManager(this); QNetworkReply *reply = m_NetworkMngr-&gt;get(QNetworkRequest(QUrl(url))); QEventLoop loop; connect(reply, SIGNAL(finished()), &amp;loop, SLOT(quit())); loop.exec(); QUrl aUrl(url); QFileInfo fileInfo=aUrl.path(); QFile file(aPathInClient+"\\"+fileInfo.fileName()); file.open(QIODevice::WriteOnly); file.write(reply-&gt;readAll()); delete reply; loop.quit(); } </code></pre> <p>This is the function that calls downloadFile():</p> <pre><code>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui-&gt;setupUi(this); downloadFile("link", "stuff"); QFile info("stuff\\info.txt"); if(info.open(QIODevice::ReadOnly)) { QTextStream in(&amp;info); while(!in.atEnd()) { version = in.readLine(); versionLink = in.readLine(); vidLink = in.readLine(); } } info.close(); setCentralWidget(ui-&gt;tabWidget); ui-&gt;creativeFlag-&gt;setEnabled(false); ui-&gt;structures-&gt;setEnabled(false); ui-&gt;raining-&gt;setEnabled(false); ui-&gt;thundering-&gt;setEnabled(false); ui-&gt;hardcore-&gt;setEnabled(false); AddSlotsToGroup(); AddBlocksToGroup(); QPalette palette = ui-&gt;blockFrame-&gt;palette(); palette.setColor( backgroundRole(), QColor( 139, 139, 139 ) ); ui-&gt;blockFrame-&gt;setPalette( palette ); ui-&gt;blockFrame-&gt;setAutoFillBackground( true ); QPixmap map_bg(":/images/mapbg.png"); ui-&gt;mapBgLabel-&gt;setPixmap(map_bg.scaled(224, 224, Qt::IgnoreAspectRatio, Qt::FastTransformation)); QShortcut *returnShortcut = new QShortcut(QKeySequence("Return"), ui-&gt;tab_4); QObject::connect(returnShortcut, SIGNAL(activated()), ui-&gt;blockFind, SLOT(click())); } </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