Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

'Unable to handle unregistered datatype' when trying to use QVector in Repeater



  • I'm trying to get a list of Channel objects to do something with them in a QML Repeater, but only get the following error message when trying to access the relevant property (actual namespace names replaced):

    QMetaProperty::read: Unable to handle unregistered datatype 'QVector<ns1::ns2::Channel*>' for property 'ns1::ns2::Room::channels'
    

    Now, the types Channel and Room are both registered to the QML engine, as well as a corresponding evocation of qRegisterMetaType for their pointer derivatives:

    qRegisterMetaType<Channel*>("Channel*");
    qRegisterMetaType<Room*>("Room*");
    //...
    qmlRegisterUncreatableType<Channel>("ns", 1, 0, "Channel", "const");
    qmlRegisterUncreatableType<Room>("ns", 1, 0, "Room", "const");
    

    Room and Channel both inherit from QObject (through a number of other types). Room has the property I'm trying to access:

    class Room : public QObject {
      // ...
      Q_PROPERTY(QVector<ns1::ns2::Channel*> channels READ channelReferences NOTIFY channelReferencesChanged)
      // ...
      Q_INVOKABLE QVector<ns1::ns2Channel*>& channelReferences() { return m_channels; }
      // ...
    signals:
      void channelReferencesChanged();
      // ...
    private:
      QVector<Channel*> m_channels;
    }
    

    I then try to access said property from QML:

    Repeater {
        model: parent.controller.room.channels // parent.controller is a different class, its 'room' property returns a Room*
        delegate: RoundButton {
            radius: 5
            text: "foo"
        }
    }
    

    I cannot find anything that is missing in order to use the C++ objects on the QML side. In fact, I'm doing something very similar with a different class and it works quite nicely.


Log in to reply