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. What does QML call QApplication? As in the C++ application intialization creates a QApplication instance.
Forum Updated to NodeBB v4.3 + New Features

What does QML call QApplication? As in the C++ application intialization creates a QApplication instance.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 571 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.
  • V Offline
    V Offline
    VFCraig
    wrote on 3 Nov 2021, 19:47 last edited by
    #1

    In C++, in main, we create a QApplication instance/object. I have created an event filter in it to monitor user activity, or more appropriately, lack of activity. (If the app is idle for too long, dialogs and menus are to be closed.) It also has a signal to be emitted when activity is detected.

    On the QML side I need to Connect to that object so I can receive the signal. I use this signal to reset a timer. If the timer goes off before being reset, it indicates no activity in the allotted time and any dialogs/menus are closed.

    QML appears to have an "Application" object and an "ApplicationWindow" object, but there is no documentation indicating what these are. I've tried enough wild guesses on my own, now I'm hoping someone knows how to refer to the QApplication object in QML so that I can connect and receive the signal.

    Thanks in advance.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fcarney
      wrote on 3 Nov 2021, 20:11 last edited by fcarney 11 Mar 2021, 20:12
      #2

      https://stackoverflow.com/questions/53247650/access-application-version-from-within-qml ?

      Edit:
      Duck Duck Go search string: "qml accessing qapp"

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1
      • V Offline
        V Offline
        VFCraig
        wrote on 3 Nov 2021, 21:26 last edited by
        #3

        Thanks, because "qml 5.15 how to access qapplication in qml" didn't work, or several other similar searches.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fcarney
          wrote on 3 Nov 2021, 21:27 last edited by
          #4

          Searching can be an art.

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            GrecKo
            Qt Champions 2018
            wrote on 4 Nov 2021, 09:15 last edited by GrecKo 11 Apr 2021, 09:16
            #5

            This won't let you access the actual QGuiApplication instance.

            QML appears to have an "Application" object and an "ApplicationWindow" object, but there is no documentation indicating what these are.

            I'm very confused by this statement.

            Qt.application's documentation says : "The application object provides access to global application state properties shared by many QML components."

            Application in Qt 6 is a singleton meant to replace the above. Its doc says : "The Application singleton exposes a subset of QApplication's properties to QML applications."

            We can see in both doc the list of properties or signals it exposes. It exposes properties of the QApplication but not the actual instance.

            As for ApplicationWindow the doc says "ApplicationWindow is a Window which makes it convenient to add a menu bar, header and footer item to the window." so it's just a Window with more features, akin to QMainWindow in the widgets world.

            Regarding your original question, you can expose a c++ object like always with the methods mentionned here https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html
            qmlRegisterSingletonInstance seems to fit the bill in your use case.

            1 Reply Last reply
            1
            • V Offline
              V Offline
              VFCraig
              wrote on 4 Nov 2021, 14:30 last edited by
              #6

              Got it working.

              Initially tried to inherit QApplication and incorporate the eventFilter and the signal to be sent in there. That didn't work.

              Then sorted through Grecko's suggestion, which BTW, qmlRegisterSingletonInstance appears nowhere in the link provided, initially trying to make the QApplication object accessible from QML.
              That didn't work.

              Finally got it to work by making the custom object containing the eventFilter and signal accessible from QML (you would think that, installEventFilter, would reparent the object, but then again a custom QApplication that incorporated one didn't work either) and that allowed it to work.

              1 Reply Last reply
              0

              1/6

              3 Nov 2021, 19:47

              • Login

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