Syntexs for Inheritance in C++



  • I am confuse for some syntex about the Inheritance in QML and C++.

    It will show error message "qrc:/QML/Resources/Qml/DesignArea.qml:32: Error: Unknown method parameter type: AppGraphicsList"* when I run below code.

    But I am sure I had include :AppGraphicsList.h" in File '".

    Why???

    %%% in main.cpp
    AppGraphicsList * graphicPath = new AppGraphicsList();
    int main(int argc, char *argv[])
    {
    ...
    ctext->setContextProperty("widget_graphicPath",graphicPath);
    ...
    }

    %%% in Design.qml

    Component.onCompleted: {
    mainWindow.setGraphicList(widget_graphicPath);
    }
    WorkArea{
    id:mainWindow
    objectName: "mainWin"
    anchors.fill: parent
    }

    %%% in workarea.h
    class WorkArea : public QQuickPaintedItem
    {
    Q_OBJECT
    public:
    WorkArea();
    ~WorkArea();
    public slots:
    void setGraphicList(AppGraphicsList *graphicPath);
    }

    %%% in graphicslist.h
    class GraphicsList : public QObject
    {
    Q_OBJECT
    public:
    explicit GraphicsList(QObject *parent = 0);
    ...
    }

    %%% in AppGraphicsList.h
    class AppGraphicsList:public GraphicsList
    {
    public:
    // AppGraphicsList();
    }

    %%%

    The werid thing is that code would be OK when I change " void setGraphicList(AppGraphicsList *graphicPath);"
    to
    " void setGraphicList(GraphicsList *graphicPath);".
    as below code:

    WHY???

    %%% in main.cpp
    AppGraphicsList * graphicPath = new AppGraphicsList();
    int main(int argc, char *argv[])
    {
    ...
    ctext->setContextProperty("widget_graphicPath",graphicPath);
    ...
    }

    %%% in Design.qml

    Component.onCompleted: {
    mainWindow.setGraphicList(widget_graphicPath);
    }
    WorkArea{
    id:mainWindow
    objectName: "mainWin"
    anchors.fill: parent
    }

    %%% in workarea.h
    class WorkArea : public QQuickPaintedItem
    {
    Q_OBJECT
    public:
    WorkArea();
    ~WorkArea();
    public slots:
    void setGraphicList(GraphicsList *graphicPath);
    }

    %%% in graphicslist.h
    class GraphicsList : public QObject
    {
    Q_OBJECT
    public:
    explicit GraphicsList(QObject *parent = 0);
    ...
    }

    %%% in AppGraphicsList.h
    class AppGraphicsList:public GraphicsList
    {
    public:
    // AppGraphicsList();
    }


  • Moderators

    @zenghsing
    Qt and especially the QML framework heavily depend on the meta object system for meta data.
    The QML engine is missing some meta data about your AppGraphicsList class, because this class is missing the Q_OBJECT macro.



  • @raven-worx

    Its true. Thanks~~~


Log in to reply
 

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