Call QML function directly from Qt(C++) in 4.8
-
Hi,
Did you try "this":http://qt-project.org/doc/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#invoking-qml-methods ?
-
Oh... I'm sorry I've use Qt5.3 and post sample from Qt5.3 doc. I've found this code:
@
// main.cpp
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, "MyItem.qml");
QObject *object = component.create();QVariant returnedValue;
QVariant msg = "Hello from C++";
QMetaObject::invokeMethod(object, "myQmlFunction",
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, msg));qDebug() << "QML function returned:" << returnedValue.toString();
delete object;
@Sorry I can't check it now because I don't have Qt 4.8 on my PC. But this code from official Qt4.8 documentation. You can use this "link":http://qt-project.org/doc/qt-4.8/qtbinding.html#calling-functions for more information.
-
Hi shav , It is working fine, but I can't able to access the components (like Image,rectangle) in that QML functions... while try to access below error is through .....
QObject::installEventFilter(): Cannot filter events for objects in a different thread.
QPixmap: It is not safe to use pixmaps outside the GUI thread