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. qvariant_cast - can't retrieve custom class pointer from QML
Qt 6.11 is out! See what's new in the release blog

qvariant_cast - can't retrieve custom class pointer from QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 350 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.
  • SeeLookS Offline
    SeeLookS Offline
    SeeLook
    wrote on last edited by SeeLook
    #1

    My QML code reads pointer of custom class and invokes C++ code with this pointer as a parameter.
    Then qvariant_cast<MyClass*> returns it.
    It works fine under Linux (GCC), but under Windows (mingw) doesn't. It returns just int value with address there.
    I had declarations Q_DECLARE_METATYPE(MyClass*) in class header and qRegisterMetaType<MyClass*>("MyClass*") before cast is performed.

    What I missing?

    1 Reply Last reply
    0
    • SeeLookS Offline
      SeeLookS Offline
      SeeLook
      wrote on last edited by
      #2

      OK. Never mind...
      I found the solution.
      QML part read MyClass pointer from other C++ side, exactly as it is - underlying C++ returned bare <MyClass*>.
      I changed that to QVariant::fromValue(myClassPtr) so now it is properly redirected further.
      Poor Win by the way.

      1 Reply Last reply
      2

      • Login

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