Quantcast
Viewing all articles
Browse latest Browse all 4972

Beginner Question: Connecting to QML Signals

Hey, i try to connect cpp with QML and had a build Error that i can’t resolve. I copyed the code based on website (doc-snapshot.qt-project.org/5.0/qtqml/qtqml-cppintegration-interactqmlfromcpp.html) Subtopic “Connecting to QML Signals” // MyItem.qml import QtQuick 2.0   Item {     id: item     width: 100; height: 100       signal qmlSignal(string msg)       MouseArea {         anchors.fill: parent         onClicked: item.qmlSignal("Hello from QML")     } } class MyClass : public QObject {     Q_OBJECT public slots:     void cppSlot(const QString &msg) {         qDebug() << "Called the C++ slot with message:" << msg;     } };   int main(int argc, char *argv[]) {     QGuiApplication app(argc, argv);       QQuickView view(QUrl::fromLocalFile("MyItem.qml"));     QObject *item = view.rootObject();       MyClass myClass;     QObject::connect(item, SIGNAL(qmlSignal(QString)),                      &myClass, SLOT(cppSlot(QString)));       view.show();     return app.exec(); } If i try to run it i get the error: Error:C2440: ‘Initialition’: ‘QQuickView’ can not in ‘QObject *’ convert ***(i translate the error from german to english) Have any one a good tip to solve this ? I try some variants with dynamic cast i found on stack overflow but without any success :( Thank you for your help !

Viewing all articles
Browse latest Browse all 4972

Trending Articles