Important: Please read the Qt Code of Conduct -

'qt_metatype_id' is not a member of...

  • I have a pretty straightforward question. i am getting the error @/usr/include/qt4/QtCore/qmetatype.h:169: error: ‘qt_metatype_id’ is not a member of ‘QMetaTypeId<QList<MOCourse*> >’@ when I attempt to execute the following code. Anyone have any ideas?

    Here is the code that triggers the issue...
    QDeclarativeView *view = w->getDeclarativeView();
    QDeclarativeContext *ctxt = view->rootContext();
    //line with the error
    ctxt->setContextProperty("course100Model", QVariant::fromValue(courseList));

    And here is the header for MOCourse, where you can see that I have declared the metatype for the pointer at the bottom.

    #ifndef MOCOURSE_H
    #define MOCOURSE_H

    #include <QString>
    #include <vector>
    #include <QObject>
    #include <QMetaType>

    using namespace std;

    class MOCourse : public QObject

    Q_PROPERTY(QString name READ name WRITE setName)
    Q_PROPERTY(QString number READ number WRITE setNumber)
    Q_PROPERTY(QString image READ image WRITE setImage)
    Q_PROPERTY(QString desc READ desc WRITE setDesc)

    // Default constructor
    MOCourse(QString n, QString num, QString pic, QString d);
    // Whether the course object was modified during the course of execution
    bool modified;
    // Row in database table
    int ID;
    // Course level
    int level;
    // Full description of course
    QString description;
    // File path of this course's large picture
    QString picture;
    // File path of this course's iconic picture
    QString icon;
    // Course title (ex. CS205 Software Engineering)
    QString courseNumber;
    QString courseTitle;
    // Vector of IDs linking to relevant demos
    vector<int> demoIDs;
    // Vector of text blurbs from opinions
    QString opinions;
    // Vector of text blurbs from interviews
    // TODO: replace with interview object
    QString interviews;

    QString name() const;
    QString number() const;
    QString image() const;
    QString desc() const;

    public slots:
    void setName(QString s);
    void setNumber(QString s);
    void setImage(QString s);
    void setDesc(QString s);


    #endif // MOCOURSE_H


  • Be aware that <code>MOCourse*</code> and <code>QList<MOCourse*></code> are two different types. If you want to store the latter one in a QVariant you will have to declare it as meta type as well.

  • Okay, that solved my first problem. Thanks for that Lukas.

    However I am now getting the error @Unable to assign QList<MOCourse*> to QDeclarativeListModel*@ in my QML file. Any idea how to fix this? I did not find any relevant information online.

Log in to reply