Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. [SOLVED] Passing QML variant to C++ method
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Passing QML variant to C++ method

Scheduled Pinned Locked Moved Game Development
3 Posts 2 Posters 2.9k 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.
  • T Offline
    T Offline
    t3685
    wrote on last edited by
    #1

    Hi,

    I'm trying to make a game where I have to able to create and move game pieces around a board. The way my code is setup now is I have a C++ object that acts as the game engine and C++ objects that act as the game pieces.

    I create a QML element dynamically containing a variant property which stores a pointer to the C++ game piece object.

    What would like to do now, is to be able to call a C++ method via QML, with the variant property as an argument. However, I get the error "Error: Unknown method parameter type: HivePiece*" (HivePiece* being the pointer that I store).

    Is there a way to do this? Or should I should use a different code structure?

    Thanks in advance,

    t3685

    1 Reply Last reply
    0
    • E Offline
      E Offline
      eliseev
      wrote on last edited by
      #2

      Hi,

      1. Are your object QObject derivatives?
      2. Do you register your types with Q_DECLARE_METATYPE?

      I've had issues that Qt sends QVariant of a different type than I expect, but that's probably a not related here.

      A piece of QML code (C++ part is rather obvious) how you manage objects there would be helpful to understand your implementation.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        t3685
        wrote on last edited by
        #3

        Hi,

        Thanks for the reply. I checked my code and it seems I forgot to register the class. Registering the class solved my problem :)

        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