[SOLVED] Call cpp method from qml in qt5.3
-
Hi, In qt 5.3, i have a cpp class (MainWindow) and i added a puch button on the ui. I want to click on the button, and open a window qml type "Window QML Type":http://qt-project.org/doc/qt-5/qml-qtquick-window-window.html
I successfully can do that but i want to call a cpp function from qml window directly, how can i do that?
I know that i can add a button in qml file and call cpp function by "onClicked:", i know it, but i want to call a cpp method directly after loading qml file, without clicking on any button. please help me.
I want something like that:in qml file (mail.qml)
window{
id :qmlMainWindow
color:whiteMainWindow { id : myCPPObject } //something like that myCPPObject.cppFunction()
}
//in mainwindow.h
Q_INVOKABLE void cppFunction();//in main.cpp
qmlRegisterType<MainWindow>("com.myself", 1, 0, "MainWindow");Thanks in advance...
-
Hi,
If I understood you correctly you could call function in "Component.onCompleted":http://qt-project.org/doc/qt-5/qml-qtqml-component.html#completed-signal handler.
-
Yes, that works.
Thank you very much