Results 1 to 2 of 2

Thread: Cannot assign to non-existent property "lon" lon: "3"

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Cannot assign to non-existent property "lon" lon: "3"

    I wish to see how QQmlListProperty is used. I tried the following but I am not sure if this is the correct way to do it. I got an error shown in the title.

    aa.h
    Qt Code:
    1. #ifndef IMO
    2. #define IMO
    3.  
    4. #include <QQmlListProperty>
    5. #include "DummyClass.h"
    6.  
    7. class SubClass: public QObject
    8. {
    9. Q_OBJECT
    10.  
    11. Q_PROPERTY (QQmlListProperty <DummyClass> functionWhat READ functionWhat)
    12.  
    13. public:
    14. SubClass (QObject *parent = 0);
    15. QQmlListProperty <DummyClass> functionWhat()
    16. {
    17. return QQmlListProperty <DummyClass> (this, dummyList);
    18. }
    19.  
    20. private:
    21. QList <DummyClass*> dummyList;
    22. };
    23.  
    24. #endif
    To copy to clipboard, switch view to plain text mode 

    aa.cpp
    Qt Code:
    1. #include "aa.h"
    2.  
    3. #include <QtGui/QGuiApplication>
    4. #include "qtquick2applicationviewer.h"
    5.  
    6. SubClass :: SubClass (QObject *parent) : QObject (parent)
    7. {
    8. qDebug ("In Constructor.");
    9. }
    10.  
    11. void appendDummies (QQmlListProperty<DummyClass> *property, DummyClass *dc)
    12. {
    13. qDebug ("Do nothing. Can't add to a directory using this method.");
    14. }
    To copy to clipboard, switch view to plain text mode 

    DummyClass.h
    Qt Code:
    1. #ifndef IM
    2. #define IM
    3. #include <QObject>
    4.  
    5. class DummyClass : public QObject
    6. {
    7. private:
    8. Q_OBJECT
    9. Q_PROPERTY (bool functionWhat READ functionWhat WRITE functionSetWhat)
    10. public:
    11. DummyClass (QObject *parent = 0) {}
    12.  
    13. float lat; float lon;
    14.  
    15. bool functionWhat ()
    16. {
    17. qDebug ("In functionWhat");
    18. }
    19.  
    20. public slots:
    21. void functionSetWhat (bool arg)
    22. {
    23. qDebug ("In functionWhatSlot");
    24. }
    25.  
    26. signals:
    27. void functionWhatChanged (bool arg);
    28. };
    29.  
    30. #endif
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtGui/QGuiApplication>
    2. #include "qtquick2applicationviewer.h"
    3. #include "/home/anisha/qmllistproperties/DummyClass.h"
    4. #include <QtQml>
    5. #include "/home/anisha/qmllistproperties/aa.h"
    6. int main(int argc, char *argv[])
    7. {
    8. QGuiApplication app(argc, argv);
    9.  
    10. const char* ocuui = "OCUUI"; // @uri OCUUI
    11.  
    12. qmlRegisterType <DummyClass> (ocuui, 1, 0, "DummyClass");
    13. qmlRegisterType <SubClass> (ocuui, 1, 0, "SubClass");
    14.  
    15.  
    16. QtQuick2ApplicationViewer viewer;
    17. viewer.setMainQmlFile(QStringLiteral("qml/untitled/main.qml"));
    18. viewer.showExpanded();
    19.  
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

    main.qml
    Qt Code:
    1. import QtQuick 2.0
    2. import OCUUI 1.0
    3.  
    4. Rectangle {
    5. width: 360
    6. height: 360
    7. Text {
    8. text: qsTr("Hello World")
    9. anchors.centerIn: parent
    10. }
    11.  
    12. SubClass
    13. {
    14. functionWhat:
    15. [
    16. DummyClass
    17. {
    18. lat: "2"
    19. lon: "3"
    20. }
    21. ]
    22. }
    23.  
    24.  
    25. MouseArea {
    26. anchors.fill: parent
    27. onClicked: {
    28. Qt.quit();
    29. }
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Cannot assign to non-existent property "lon" lon: "3"

    I am not sure what you are looking for. The QML engine tells you that there is no property "lon" in DummyClass and indeed there isn't.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 3rd December 2013, 02:19
  2. Replies: 1
    Last Post: 7th April 2010, 21:46
  3. Replies: 3
    Last Post: 15th February 2010, 17:27
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.