Connection on QtGUI and QML?
-
Hello
I designed an application in qml,and imported in QtGUI Application.
and now , i wanna to make connection in this between .
For Example , Wen I'm clicked on a button in qml (imported in main window) , my ui->webview got to "......" url.
can you help me?
thanks. -
I'm not sure I understand your English. I'll assume you meant "when I click a button in QML, I want my webview, declared in C++ (QtWidgets) to go to a certain URL". If that happens to be the case, the answer is quite simple. You can use signal/ slot connections to manage your communication. Or even simple Q_INVOKABLE method.
For example:
create a Qt class (it has to inherit from QObject, remember!): say, myText. There, declare something like @ Q_INVOKABLE void setWebViewUrl(const QString &newUrl); @
add this class to QML by calling @ QDeclarativeView::rootContext()->setContextObject(new myClass *instance()); @ (you have to provide a QDeclarativeView object, of course)
you can now use this new method inside your QML code, it will be available everywhere. I'll give an example for MouseArea:
@ MouseArea {
onClicked: {
setWebViewUrl("my.new.url.com")
}
} @That's it. Happy coding :)
-
Re-read 3rd point I've made. It's globally available once you add the QObject that declares it to rootContext.
-
Cheers.
If anything is still unclear or doesn't work, don't hesitate to ask.
If problem is resolved, please add [Solved] at the beginning of this topic's subject.