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. [SOLVED] accessing parameter (with non-basic type) of C++ signal

[SOLVED] accessing parameter (with non-basic type) of C++ signal

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.2k Views
  • 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.
  • M Offline
    M Offline
    morte
    wrote on last edited by
    #1

    Assume we have C++ object of type QGeoSatelliteInfoSource registered as context property
    which emits signal
    void satellitesInUseUpdated(const QList<QGeoSatelliteInfo> & satellites),

    QML-side handle that signal at Connections { onSatellitesInUseUpdated: {...} } ,
    how to use satellites parameter of type QVariant(QList<QGeoSatelliteInfo>) ?

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

      Hi,

      AFAIK it should be accessible just like accessing a JavaScript array.
      For eg:
      In C++
      @
      QVariantList list;
      list << "Data1" << "Data2" << "Data1";
      ...
      emit listData(list);
      @

      and then from QML
      @
      onListData: {
      console.log(list)
      console.log(list[0],list[1])
      }
      @

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        morte
        wrote on last edited by
        #3

        Here test output:

        @ console.log("typeof satellites", typeof satellites);
        console.log("satellites", satellites);
        console.log("satellites.size", satellites.size);
        console.log("satellites.size()", satellites.size);
        console.log("satellites[0]", satellites[0]);
        @

        @qml: typeof satellites object
        qml: satellites QVariant(QList<QGeoSatelliteInfo>)
        qml: satellites.size undefined
        qml: satellites.size() undefined
        qml: satellites[0] undefined
        @

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rolias
          wrote on last edited by
          #4

          Have you registered the C++ QGeoSatelliteInfo as a known type to QML? If you have and QList<QGeoSatelliteInfo> doesn't work you could try making it a QVariantList on the C++ side. The "data conversion docs":http://qt-project.org/doc/qt-5/qtqml-cppintegration-data.html make me think this would work, whereas they aren't specific about QList<T> except for basic types for T.

          Check out my third course in the trilogy on Qt
          "Integrating Qt Quick with C++"
          http://bit.ly/qtquickcpp
          published by Pluralsight

          1 Reply Last reply
          0
          • M Offline
            M Offline
            morte
            wrote on last edited by
            #5

            Thanks for replies. No, QGeoSatelliteInfo is not registered because i wanted just to get size of the list. I have read in docs that List<T> where T is non-basic type cant be used for transfer sequences to QML and QList isn't QObject derived class. QQmlListProperty<> should be used for that purpose. So anyway making an new 'proxy' class at C++ side is needed.

            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