error: variable 'QQmlComponent component' has initializer but incomplete type in Qt5

后端 未结 2 597
说谎
说谎 2021-01-27 13:18

i am playing with Exposing Attributes of C++ Types to QML in Qt5 based on this tutor http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-exposecppattributes.html. when i

相关标签:
2条回答
  • 2021-01-27 13:51

    You are not including QQmlComponent header in your main.cpp:

    #include <QQmlComponent>
    

    You are also trying to emit a signal that you haven't declared yet. You should declare it in your message.h like this:

    signals:
        void authorChanged();
    

    Check this example.

    0 讨论(0)
  • 2021-01-27 14:01

    I believe you need to add:

    signals: 
      void authorChanged();
    

    to your class like this:

      class Message : public QObject
    {
    Q_OBJECT
    Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
    public:
        void setAuthor(const QString &a) {
            if (a != m_author) {
                m_author = a;
                emit authorChanged();
            }
        }
        QString author() const {
            return m_author;
        }
    signals:
      void authorChanged();
    private:
        QString m_author;
    };
    
    0 讨论(0)
提交回复
热议问题