Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Calling Qt.quit() during setup
Forum Updated to NodeBB v4.3 + New Features

Calling Qt.quit() during setup

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 4 Posters 1.4k Views 3 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.
  • PhrogzP Offline
    PhrogzP Offline
    Phrogz
    wrote on last edited by Phrogz
    #1

    Here's a test app. main.cpp is default boilerplate with quit() signal connected. I want to quit the application (from QML) as it is starting up.

    Without the Timer shown below, the application does not quit. With the Timer, it instantly quits as desired (before the window even shows up). Is there a cleaner way to ensure the quit() will work?

    import QtQuick 2.8
    import QtQuick.Window 2.2
    Window {
        visible:true; width:640; height:480; color:'red'; title:'Quit Test'
        Component.onCompleted: Qt.quit()
        // Timer { interval:1; running:true; onTriggered:Qt.quit() }
    }
    

    Motivation: I have a command-line-argument parser in QML; when it detects --help or -h (during Component.onCompleted), or when a required argument is omitted, it should print the help and quit the application.

    kshegunovK 1 Reply Last reply
    0
    • PhrogzP Phrogz

      Here's a test app. main.cpp is default boilerplate with quit() signal connected. I want to quit the application (from QML) as it is starting up.

      Without the Timer shown below, the application does not quit. With the Timer, it instantly quits as desired (before the window even shows up). Is there a cleaner way to ensure the quit() will work?

      import QtQuick 2.8
      import QtQuick.Window 2.2
      Window {
          visible:true; width:640; height:480; color:'red'; title:'Quit Test'
          Component.onCompleted: Qt.quit()
          // Timer { interval:1; running:true; onTriggered:Qt.quit() }
      }
      

      Motivation: I have a command-line-argument parser in QML; when it detects --help or -h (during Component.onCompleted), or when a required argument is omitted, it should print the help and quit the application.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Phrogz said in Calling Qt.quit() during setup:

      Is there a cleaner way to ensure the quit() will work?

      I don't believe so. You could use zero interval to queue it immediately in the event loop, beside that the code looks okay to me.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1
      • Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @progpow Have you checked the documentation for Qt.quit()?

        Not sure how you're launching the QML application, but if you're using QQmlEngine from a C++ application, you might want to consider using the QCommandLineParser class to handle all the command line arguments there before even launching the QML part.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        2
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Out of curiosity, why go all the way to the GUI when you have known option(s) that should basically not even trigger it ?

          It would make more sense to use the QCommandLineParser class for options that should be handled outside your application GUI.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          PhrogzP 1 Reply Last reply
          3
          • SGaistS SGaist

            Hi,

            Out of curiosity, why go all the way to the GUI when you have known option(s) that should basically not even trigger it ?

            It would make more sense to use the QCommandLineParser class for options that should be handled outside your application GUI.

            PhrogzP Offline
            PhrogzP Offline
            Phrogz
            wrote on last edited by
            #5

            @SGaist It makes more sense to a C++ programmer for sure. I'm not a C++ programmer; I'm writing full applications in QML/JS with 12 lines of C++ provided by the new project template to keep me afloat. :)

            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