[SOLVED] How to access QQmlApplicationEngine?



  • 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



  • 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.



  • 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();

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.