Hello together, are there some changes between Qt5.2 and Qt5.3 regarding to signal and slots behaviour?
I've tried to switch to Qt5.3 but my Signals and Slots with QVariant are not working between QML and C++. I've written a small example that is working fine with Qt5.2 but not with Qt5.3. I get the following error during start-up of the application compiled with Qt5.3: QObject::connect: No such signal QQuickWindowQmlImpl_QML_0::qmlSignal(QVariant) in ../qml_cpp_signal_slots/main.cpp:20 <../qml_cpp_signal_slots/main.cpp:20> Please see the attatched sources. Any ideas? Thanks and Best Regards, railwaycoder
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QDebug> #include <QQuickItem> #include <myclass.h> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); QObject *item = engine.rootObjects().at(0); MyClass myClass; QObject::connect(item, SIGNAL(qmlSignal(QVariant)), &myClass, SLOT(cppSlot(QVariant))); return app.exec(); }
import QtQuick 2.2 import QtQuick.Window 2.1 Window { visible: true width: 360 height: 360 id: test signal qmlSignal(var anObject) MouseArea { anchors.fill: parent onClicked: { test.qmlSignal(test) console.log("qml: clicked!") } } Text { text: qsTr("Hello World") anchors.centerIn: parent } }
#include "myclass.h" MyClass::MyClass(QObject *parent) : QObject(parent) { }
#ifndef MYCLASS_H #define MYCLASS_H #include <QObject> #include <QDebug> #include <QQuickWindow> class MyClass : public QObject { Q_OBJECT public: explicit MyClass(QObject *parent = 0); signals: public slots: void cppSlot(const QVariant &v) { qDebug() << "Called the C++ slot with value:" << v; QQuickWindow *item = qobject_cast<QQuickWindow*>(v.value<QObject*>()); qDebug() << "Item dimensions:" << item->width() << item->height(); } }; #endif // MYCLASS_H
qml.qrc
Description: Binary data
qml_cpp_signal_slots.pro
Description: Binary data
deployment.pri
Description: Binary data
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest