[Solved] Receiving signals from QML to C++
-
wrote on 17 Jun 2011, 16:39 last edited by
I see two problems here.
-
At first, your QML file is processed before the context property is added.
@
QDeclarativeView view(QUrl::fromLocalFile("qml/fileTrenner2/main.qml"));
view.rootContext()->setContextProperty("myObject", &funz);
@ should probably read
@
QDeclarativeView view;
view.rootContext()->setContextProperty("myObject", &funz);
view.setSource(QUrl::fromLocalFile("qml/fileTrenner2/main.qml"));
@ -
At second, you add the context property to the root context of view (the QDeclarativeView) and not viewer (the QmlApplicationViewer, which is in fact just a wrapper around another QDeclarativeView). view is actually never shown, the corresponding code can be removed completely.
-
-
wrote on 17 Jun 2011, 17:19 last edited by
bq. QDeclarativeView view;
view.rootContext()->setContextProperty("myObject", &funz);
view.setSource(QUrl::fromLocalFile("qml/fileTrenner2/main.qml"));thank you. you were very clear, but i do not understand why do you declare the QDeclarativeView making save to explain immediatly the file toward which methods will be applied. i mean: where is the conceptual or tecnical difference between the two snippets?
i will use the QDeclarativeView.
-
wrote on 17 Jun 2011, 17:27 last edited by
The qml is being processed as soon as you call setSource (whether directly or indirectly through the constructor). From the documentation:
[quote]
source : QUrl
This property holds the URL of the source of the QML component.
Changing this property causes the QML component to be reloaded.
[/quote]
Therefore, you have to add any special object and context variables before you use setSource. Otherwise they will not be present when (re)loading the qml. Does that make sense to you now? -
wrote on 17 Jun 2011, 17:37 last edited by
this is an excellent answer! ;)
-
wrote on 17 Jun 2011, 19:02 last edited by
ideas for closing the program?
-
wrote on 17 Jun 2011, 19:29 last edited by
If you want to close your program from QML use Qt.quit().
-
wrote on 17 Jun 2011, 19:34 last edited by
error: Signal QDeclarativeEngine::quit() emitted, but no receivers connected to handle it.
-
wrote on 17 Jun 2011, 19:47 last edited by
You have to connect the QDeclarativeEngine::quit() signal to the QApplication::quit() slot.
@
connect(view->engine(), SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
@Don't forget to add "[Solved]" to topic titles which have been solved for you.
-
wrote on 17 Jun 2011, 20:26 last edited by
[OFFTOPIC]
I would kindly like to propose to change the word "Reciving" in the title of the thread to "Receiving". :-)
[/OFFTOPIC] -
wrote on 18 Jun 2011, 09:01 last edited by
so, that was made!
how to choose the solver in this thread? -
wrote on 18 Jun 2011, 17:49 last edited by
[quote author="spode" date="1308387674"]so, that was made!
how to choose the solver in this thread?[/quote]Um... what?
If the question is related to this [quote author="Lukas Geyer" date="1308340073"]Don't forget to add "[Solved]" to topic titles which have been solved for you.[/quote] just click the edit button on your first post an change the title from "Receiving signals from QML to C++" to "[Solved] Receiving signals from QML to C++".
18/19