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. QML + QEnums
Forum Updated to NodeBB v4.3 + New Features

QML + QEnums

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 3.1k 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.
  • B Offline
    B Offline
    bunjee
    wrote on last edited by
    #1

    Greetings Qt community,

    I'm calling this function from QML:
    @Q_INVOKABLE OtherClass::Type Class::getType() const;@
    In the QML:
    @property int type: -1

    type = class.getType();@
    I get the following message:
    @'Cannot assign [undefined] to int'@

    The enum is declared with Q_ENUM in the OtherClass. And I declared OtherClass with qmlRegisterType.

    Am I missing something ?

    Thanks.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dmcr
      wrote on last edited by
      #2

      Hello,

      I don't think it's possible to do that (your syntax seems ok)
      I have tried it a time ago, but i finally cast the value int for using it in QML side.

      dmcr

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SteveKing
        wrote on last edited by
        #3

        Hi,

        I ended up doing the same as dmcr... It seems that Q_ENUMS work correctly in QML for comparisons, assignment and as function arguments but don't work when passed from C++ as either function return values or signal arguments.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chriadam
          wrote on last edited by
          #4

          Hi SteveKing,

          That sounds like a bug. Can you confirm that it's still the case in QtQuick2? If so, please file a bug report.

          Cheers,
          Chris.

          /edit: I should add - there is some special considerations with enums (and the QMetaObject extension stuff) which I'm not too familiar, so perhaps the fact that the source of the type information is a separate QMetaObject, is the issue in this particular case. I don't know. Either way, it should work - whether or not it's technically feasible to fix is another question...

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SteveKing
            wrote on last edited by
            #5

            Hi Chris,

            I'm not using Qt5 (QtQuick2) yet so I don't know if it's there. I think this might be related to existing bugs: "15983":https://bugreports.qt-project.org/browse/QTBUG-15983 and "27041":https://bugreports.qt-project.org/browse/QTBUG-27041

            Regards,
            Steve

            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