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. [SOLVED] How to access QQmlApplicationEngine?

[SOLVED] How to access QQmlApplicationEngine?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 2.7k 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.
  • M Offline
    M Offline
    morker
    wrote on 17 Nov 2014, 12:32 last edited by
    #1

    Hi,

    I set in my main method my QQmlApplicationEngine and load my main.qml. I need to access the engine in another class.

    What is the best approach to do that? Global variable? Something similar to "QSqlDatabase::database("myDatabase");"

    Thanks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andresantos
      wrote on 5 May 2015, 15:50 last edited by
      #2

      Not sure if this is the best method, but I would create a singleton with a QQmlApplicationEngine pointer variable and in your main pass the QQmlApplicationEngine instance to the singleton. This way you can access it everywhere.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexvplay
        wrote on 5 May 2015, 16:10 last edited by
        #3

        What's your class' superclass where you need the reference to the engine?

        If you only need the instance of the current QQmlEngine within a QQuickItem you can use a code snippet like the following:

        QQmlContext *currentContext = QQmlEngine::contextForObject(this);
        QQmlEngine *engine = currentContext->engine();
        

        CoFounder of Felgo - https://felgo.com/qt

        Felgo simplifies Mobile App & Game Development with Qt
        What others say: Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

        1 Reply Last reply
        1

        • Login

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