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



  • 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>) ?


  • Moderators

    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])
    }
    @



  • 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
    @



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.