[SOLVED] How to access QQmlApplicationEngine?
-
wrote on 17 Nov 2014, 12:32 last edited by
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
-
wrote on 5 May 2015, 15:50 last edited by
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.
-
wrote on 5 May 2015, 16:10 last edited by
What's your class' superclass where you need the reference to the engine?
If you only need the instance of the current
QQmlEngine
within aQQuickItem
you can use a code snippet like the following:QQmlContext *currentContext = QQmlEngine::contextForObject(this); QQmlEngine *engine = currentContext->engine();