Problem interacting with qml object from c++, qt5
-
@// Using QQuickView
QQuickView view;
view.setSource(QUrl::fromLocalFile("MyItem.qml"));
view.show();
QObject object = view.rootObject();
@
i'm copypasting this code from ("doc":http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-interactqmlfromcpp.html
but it's not working, QTCreator print error: "cannot convert 'QQuickItem' to 'QObject*' in initialization"
Why? -
@
QQuickItem *object = view.rootObject();
@Should work. Or casting. Or some other trick. QQuickItem is a kid of QObject anyway, so all ::findChildren<>() and ::metaObject() magic still works.
-
Hi,
today I had the same problem.
gcc Error: “cannot convert ‘QQuickItem*’ to ‘QObject*’ in initialization”
clang error: "cannot convert argument of incomplete type 'QQuickItem *' to 'QObject *'"Ah, incomplete type ... I love clang :-)
Add:
@#include<QQuickItem>@Then it works fine for me.
-
Yeah, clang rocks big time :) And now it fully supports C++11, too.