Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Issues of Q_DECLARE_METATYPE in establishing signal & slot connection
Forum Updated to NodeBB v4.3 + New Features

Issues of Q_DECLARE_METATYPE in establishing signal & slot connection

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 1 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    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.cpp

    I 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&#40;"test.qml"&#41;);@
    

    But it is throwing compile time error "redefinition of 'struct qmetatypeid"
    any idea what i have missed...thanks

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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?

          (Z(:^

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved