A
A
Alexander2014-12-02 08:25:31
Qt
Alexander, 2014-12-02 08:25:31

Is it possible to get the currently loaded QQmlApplicationEngine from an arbitrary class?

The engine is loaded in main.cpp

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

and my custom class whose methods are available in Qml.
How can I make it so that I can call some function Foo () of my class from Qml, which would load a new component on the current form?
Those. the problem itself is in getting a link to the current engine, I know how to call the function.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2014-12-02
@gbg

New components can be added directly to qml:

Button  {                 
        text: "Click to create dynamic component"
        onClicked :  {                     
            // Create the component and add it to the Container  
            var createdControl = compDef.createObject();
            rootContainer.add(createdControl);
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question