Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Syntexs for Inheritance in C++
Forum Updated to NodeBB v4.3 + New Features

Syntexs for Inheritance in C++

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 940 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.
  • zenghsingZ Offline
    zenghsingZ Offline
    zenghsing
    wrote on last edited by zenghsing
    #1

    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();
    }

    raven-worxR 1 Reply Last reply
    0
    • zenghsingZ zenghsing

      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();
      }

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      zenghsingZ 1 Reply Last reply
      2
      • raven-worxR raven-worx

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

        zenghsingZ Offline
        zenghsingZ Offline
        zenghsing
        wrote on last edited by
        #3

        @raven-worx

        Its true. Thanks~~~

        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