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. Cath the event of quit from application
Forum Updated to NodeBB v4.3 + New Features

Cath the event of quit from application

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 2.1k Views 1 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.
  • I Offline
    I Offline
    ixpervision
    wrote on last edited by
    #1

    hi everyone;

    i m new in Qt world. i make a simple application as Qt Quick Application. App wizard creat
    qtquick2applicationviewer.h, qtquick2applicationviewer.cpp, main.cpp and main qml file .İn main.cpp file app wizard
    creat a object as QtQuick2ApplicationViewer for display qml file. i write in qml file this codes for simple rectangle

    @
    import QtQuick 2.0
    Rectangle {
    id:basitButon
    width:100; height:100

    MouseArea{
        id:mouseAlani
        anchors.fill:parent
        hoverEnabled: true
    
    }
    

    }@

    And i want to catch when users want to quit applicaiton. For example when user press the back key ,i want to make a dialog "are you sure to close app " as window.I hope I could tell wanted to do.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      There are a couple of things you need to do.
      First you should perhaps use the appwizard that creates a QtQuick.Controls application for you, simply because it will create a MainWindow as the root of your application. When you have done this you will get an onClosing event that provides exactly what you are looking for.

      (note you also get this with QtQuick.Window 2.1 as well)

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ixpervision
        wrote on last edited by
        #3

        can you give me a simple example?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jens
          wrote on last edited by
          #4

          I havent tested but from the documentation this should work:

          @
          Window {
          onClosing: {
          if (ignoreCloseForSomeReason)
          close.accepted = false
          }
          }
          @

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ixpervision
            wrote on last edited by
            #5

            When I trying these codes,I'm encountering these errors

            If your example is using QML 2, (such as qmlscene) and the .qml file you
            loaded has 'import QtQuick 1.0' or 'import Qt 4.7', this error will occur.

            To load files with 'import QtQuick 1.0' or 'import Qt 4.7', use the
            QDeclarativeView class in the Qt Quick 1 module.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jens
              wrote on last edited by
              #6

              As I mentioned earlier you need to create a completely new project using the wizard in creator that targets Qt Quick Controls. If you use a QQuickView to show your QML code, QML has no control over window creation or destruction as QQuickView itself is a Widget/Window and can only be controlled from C++.

              1 Reply Last reply
              0
              • I Offline
                I Offline
                ixpervision
                wrote on last edited by
                #7

                ok, I will try controll from c++. Thank you for interest

                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