Details
-
Bug
-
Resolution: Cannot Reproduce
-
P2: Important
-
None
-
5.3.0
-
None
-
- OS: Ubuntu 14.04
- Qt: 5.3, Qt Creator 3.1.1
- Compiler: g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Description
Sample code given in the documentation section "Exposing Attributes of C++ Types to QML" fails to compile due to wrong usage of the QQmlListProperty constructor.
Link to the doc page: http://qt-project.org/doc/qt-5/qtqml-cppintegration-exposecppattributes.html
This is my implementation of the given sample:
main.cpp
#include <QGuiApplication> #include <QtQuick> #include <QtQml> 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; }; class MessageBoard : public QObject { Q_OBJECT Q_PROPERTY(QQmlListProperty<Message> messages READ messages) public: QQmlListProperty<Message> messages() const { return QQmlListProperty<Message>(this, 0, &MessageBoard::append_message); } private: static void append_message(QQmlListProperty<Message> *list, Message *msg) { MessageBoard *msgBoard = qobject_cast<MessageBoard *>(list->object); if (msg) msgBoard->m_messages.append(msg); } QList<Message *> m_messages; }; int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); qmlRegisterType<Message>(); return app.exec(); } #include "main.moc"
This is the compilation error:
main.cpp: In member function 'QQmlListProperty<Message> MessageBoard::messages() const': main.cpp:32:80: error: no matching function for call to 'QQmlListProperty<Message>::QQmlListProperty(const MessageBoard* const, int, void (*)(QQmlListProperty<Message>*, Message*))' return QQmlListProperty<Message>(this, 0, &MessageBoard::append_message); ^ main.cpp:32:80: note: candidates are: In file included from /opt/Qt/5.3/gcc_64/include/QtQml/qqml.h:48:0, from /opt/Qt/5.3/gcc_64/include/QtQml/QtQml:9, from /opt/Qt/5.3/gcc_64/include/QtQuick/QtQuickDepends:4, from /opt/Qt/5.3/gcc_64/include/QtQuick/QtQuick:3, from main.cpp:2: /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:73:5: note: QQmlListProperty<T>::QQmlListProperty(QObject*, void*, QQmlListProperty<T>::CountFunction, QQmlListProperty<T>::AtFunction) [with T = Message; QQmlListProperty<T>::CountFunction = int (*)(QQmlListProperty<Message>*); QQmlListProperty<T>::AtFunction = Message* (*)(QQmlListProperty<Message>*, int)] QQmlListProperty(QObject *o, void *d, CountFunction c, AtFunction t) ^ /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:73:5: note: candidate expects 4 arguments, 3 provided /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:70:5: note: QQmlListProperty<T>::QQmlListProperty(QObject*, void*, QQmlListProperty<T>::AppendFunction, QQmlListProperty<T>::CountFunction, QQmlListProperty<T>::AtFunction, QQmlListProperty<T>::ClearFunction) [with T = Message; QQmlListProperty<T>::AppendFunction = void (*)(QQmlListProperty<Message>*, Message*); QQmlListProperty<T>::CountFunction = int (*)(QQmlListProperty<Message>*); QQmlListProperty<T>::AtFunction = Message* (*)(QQmlListProperty<Message>*, int); QQmlListProperty<T>::ClearFunction = void (*)(QQmlListProperty<Message>*)] QQmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c, AtFunction t, ^ /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:70:5: note: candidate expects 6 arguments, 3 provided /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:67:5: note: QQmlListProperty<T>::QQmlListProperty(QObject*, QList<T*>&) [with T = Message] QQmlListProperty(QObject *o, QList<T *> &list) ^ /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:67:5: note: candidate expects 2 arguments, 3 provided /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:65:5: note: QQmlListProperty<T>::QQmlListProperty() [with T = Message] QQmlListProperty() ^ /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:65:5: note: candidate expects 0 arguments, 3 provided /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:58:7: note: QQmlListProperty<Message>::QQmlListProperty(const QQmlListProperty<Message>&) class QQmlListProperty { ^ /opt/Qt/5.3/gcc_64/include/QtQml/qqmllist.h:58:7: note: candidate expects 1 argument, 3 provided main.cpp:33:5: warning: control reaches end of non-void function [-Wreturn-type] } ^ make: *** [main.o] Error 1 13:53:17: The process "/usr/bin/make" exited with code 2. Error while building/deploying project QtQQmlListProperty2 (kit: Desktop Qt 5.3.0 GCC 64bit) When executing step 'Make'