Issues of Q_DECLARE_METATYPE in establishing signal & slot connection
-
Hi,
I am trying to establish a connection between signal and slot and using the approach of exposing slot to QML by setContextProperty in my main.cppI have declare a slot in myClass like this
@public slots:
void cppSlot(const QString &msg) {
qDebug() << "Called the C++ slot with message:" << msg;
}-@
Then exposing it to qml in my CPP like this@ QDeclarativeView view;
MyClass- myClass;
view.rootContext()->setContextProperty("myObject", &myClass);view.setSource(QUrl::fromLocalFile("test.qml"));@
But it is throwing compile time error "redefinition of 'struct qmetatypeid"
any idea what i have missed...thanks -
How does the subject relate to your message? Are you using Q_DECLARE_METATYPE at all in your code? This code should work without declaring any new metatypes.
-
No I have not used Q_DECLARE_METATYPE in my code, and I know that this code should work without it. But recently found a link stating that it could be a bug in qt5. you can check here
https://qt-project.org/forums/viewthread/27198
I hope it is right...
-
That does not seem to be the same case, but I have only looked briefly. Are you tied to QDeclarative? Maybe you can move to QtQuick 2 and QQuickView instead?