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. Cannot close application
Forum Updated to NodeBB v4.3 + New Features

Cannot close application

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 238 Views 2 Watching
  • 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.
  • J Offline
    J Offline
    joejack77
    wrote on last edited by joejack77
    #1

    I have an issue where various Qt quit methods (QApplication::quit(), QApplication::exit(), QCoreApplication::quit(), etc.) are not working when called. Only std::exit() seems to work.

    Here's a minimal example demonstrating the issue:

    void MyClass::runLicenseCheck()
    {
        QJsonParseError parseError;
        QJsonDocument doc = QJsonDocument::fromJson(licenseData, &parseError);
        if (parseError.error != QJsonParseError::NoError) {
            qDebug() << "Failed to parse JSON:" << parseError.errorString();
    
            // None of these work:
            // QApplication::quit();
            // QApplication::exit(1);
            // QCoreApplication::quit();
            // qApp->quit();
            
            // Only this works:
            std::exit(1);
            return;
        }
    }
    

    How is this possible? Could somebody explain? Whats happening?

    Pl45m4P 1 Reply Last reply
    0
    • JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      The Qt functions exit the Qt event loop. Invoked from your main(). You do not allow code to return to that so you don't see any effect, at least depending where you call runLicenseCheck() from.

      Don't directly exit the Qt application on some license check failure, Return a failure code, clean up somewhere, exit from your main program.

      1 Reply Last reply
      0
      • J joejack77

        I have an issue where various Qt quit methods (QApplication::quit(), QApplication::exit(), QCoreApplication::quit(), etc.) are not working when called. Only std::exit() seems to work.

        Here's a minimal example demonstrating the issue:

        void MyClass::runLicenseCheck()
        {
            QJsonParseError parseError;
            QJsonDocument doc = QJsonDocument::fromJson(licenseData, &parseError);
            if (parseError.error != QJsonParseError::NoError) {
                qDebug() << "Failed to parse JSON:" << parseError.errorString();
        
                // None of these work:
                // QApplication::quit();
                // QApplication::exit(1);
                // QCoreApplication::quit();
                // qApp->quit();
                
                // Only this works:
                std::exit(1);
                return;
            }
        }
        

        How is this possible? Could somebody explain? Whats happening?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @joejack77 said in Cannot close application:

        minimal example demonstrating the issue:

        I don't think any QJsonDocument and other JSON stuff is relevant to demonstrate your issue.
        The more important part is, what @JonB also mentioned, where do you call this runLicenseCheck function and what happens before and after?


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • GaoboG Offline
          GaoboG Offline
          Gaobo
          wrote on last edited by
          #4

          the qt's document say that:

          If the event loop is not running, this function does nothing.

          1 Reply Last reply
          0

          • Login

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