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. How to pass ListModel data to C++ function

How to pass ListModel data to C++ function

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.5k 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.
  • cmessineoC Offline
    cmessineoC Offline
    cmessineo
    wrote on last edited by
    #1

    I have a ListModel in QML:

    @
    ListModel{
    id: data
    ListElement
    {
    x: 10
    y: 20
    count: 18
    }
    }

    function draw(){
    ctx.drawIntensityMap(data);
    }

    //********** c++ code

    void Context2D::drawIntensityMap(QVariantList data)
    {
    ....
    }
    @

    The model just gets populated with x,y,count data via javascript. After it gets populated I want to pass it to my c++ function so I can draw a HeatMap with QPainter.
    I can't figure out how to pass the data to my C++ function.

    Would I have to pass it as a QVariantList? If so how would I get to the data in C++.

    Thanks

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      You can iterate and add the model data into an array and pass that array as QVariantList to the C++ function.

      157

      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