Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qApp->quit() from other class not working

qApp->quit() from other class not working

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 323 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    naj_
    wrote on last edited by naj_
    #1

    Hey there,

    when I start my application I check a catalog of files if any file is missing. If there is any file missing, I show a custom messagebox (just a class which inherits from QMessageBox) to the user. In this messagebox the user has the ability to click on Exit, to quit the whole application. This is how I achieve it:

            QAbstractButton *openAnywayBtn;
            QAbstractButton *exitBtn;
            // -----------------------------
            QAbstractButton *showListBtn;
            QAbstractButton *deleteFromCatBtn;
            if (missingFiles.count() >= 20) {
                box->setBoxDescription(tr("There are more than 20 files missing in your catalog."));
                showListBtn = box->addButton(tr("Show Detailed List"), QMessageBox::ResetRole);
                openAnywayBtn = box->addButton(tr("Open anyway"), QMessageBox::YesRole);
                exitBtn = box->addButton(tr("Exit"), QMessageBox::NoRole);
            } else {
                box->setBoxDescription(_msg + _files);
                openAnywayBtn = box->addButton(tr("Open anyway"), QMessageBox::ResetRole);
                deleteFromCatBtn = box->addButton(tr("Delete from Catalog"), QMessageBox::YesRole);
                exitBtn = box->addButton(tr("Exit"), QMessageBox::NoRole);
            }
            box->exec();
            if (box->clickedButton() == exitBtn) {
                qApp->quit();
            }
    

    My main.cpp just looks like this:

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        CatalogFileList *list = new CatalogFileList("C:/Users/Jan/Desktop/DefaultCatalog");
    
        QStringList catalogFiles;
        if (list->readXml()) {
            if (list->checkFiles()) { // the check is included in this function
                catalogFiles = list->getFiles();
            }
        }
    
        QMainWindow w;
        w.showMaximized();
    
        return app.exec();
    }
    

    When the user clicks on Exit, nothing happens. The window is show and the QApplication instance is running normally. How can I achieve to close the whole application from this MessageBox. I tried out many ways (just like QObject::connect with the slot of qApp).

    Many thanks,
    Jan

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by hskoglund
      #2

      Hi, try your connect this way:

      connect(exitBtn, SIGNAL(clicked()), &qApp, SLOT(quit()), Qt::QueuedConnection);
      

      You need the QueuedConnection flavor to survive the app.exec() call, for more see here

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved