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. Custom itemModel, passing "complex variant" from QML

Custom itemModel, passing "complex variant" from QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 614 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.
  • F Offline
    F Offline
    Fede Devi
    wrote on last edited by
    #1

    I have a custom item model extending QAbstractItemModel and Implementing setData method. On the QML I can assign data to roleNames and the setData method gets called correctly with the QVariant instance but only if the data is a basic type. Is there a way to pass a QVariantMap from QML to C++ through setData?

    Example in QML:
    rolename = "string" //works fine
    rolename = {key : "value"} //does not work (QVariant is empty on c++ side)
    rolename = {"key" : "value"} //does not work (QVariant is empty on c++ side)

    1 Reply Last reply
    0
    • P Offline
      P Offline
      PhlipVR
      wrote on last edited by
      #2

      setData uses QVariant as argument probably you need to convert to QVarianMap using QVariant::toMap on c++ side

      1 Reply Last reply
      2
      • F Offline
        F Offline
        Fede Devi
        wrote on last edited by
        #3

        Thanks, that worked perfectly.

        My error was trying to convert the Variant to a JsonObject instead of a VariantMap on the c++ side.

        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