[Interest] (QQmlListProperty) Cannot assign to non-existent property "lon" lon: "3"

Anisha Kaul born.rebel.83 at gmail.com
Tue Nov 12 14:00:16 CET 2013


Greetings,

I wish to see how [B]QQmlListProperty [/B] 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
as follows:
"Cannot assign to non-existent property "lon" lon: "3"

___aa.h___

[CODE]
#ifndef IMO
#define IMO

#include <QQmlListProperty>
#include "DummyClass.h"

class SubClass: public QObject
{
  Q_OBJECT

  Q_PROPERTY (QQmlListProperty <DummyClass> functionWhat READ functionWhat)

public:
  SubClass (QObject *parent = 0);
  QQmlListProperty <DummyClass> functionWhat()
  {
    return QQmlListProperty <DummyClass> (this, dummyList);
  }

private:
  QList <DummyClass*> dummyList;
};

#endif
[/CODE]

___aa.cpp___
[CODE]
#include "aa.h"

#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"

SubClass :: SubClass (QObject *parent) : QObject (parent)
{
  qDebug ("In Constructor.");
}

void appendDummies (QQmlListProperty<DummyClass> *property, DummyClass *dc)
{
  qDebug ("Do nothing. Can't add to a directory using this method.");
}

[/CODE]

___DummyClass.h___

[CODE]#ifndef IM
#define IM
#include <QObject>

class DummyClass : public QObject
{
  private:
    Q_OBJECT
    Q_PROPERTY (bool functionWhat READ functionWhat WRITE functionSetWhat)
  public:
    DummyClass (QObject *parent = 0) {}

    float lat; float lon;

    bool functionWhat ()
    {
        qDebug ("In functionWhat");
    }

  public slots:
    void functionSetWhat (bool arg)
    {
        qDebug ("In functionWhatSlot");
    }

  signals:
    void functionWhatChanged (bool arg);
};

#endif
[/CODE]

___main.cpp___
[CODE]
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "/home/anisha/qmllistproperties/DummyClass.h"
#include <QtQml>
#include "/home/anisha/qmllistproperties/aa.h"
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    const char* ocuui = "OCUUI"; // @uri OCUUI

    qmlRegisterType <DummyClass> (ocuui, 1, 0, "DummyClass");
    qmlRegisterType <SubClass> (ocuui, 1, 0, "SubClass");


    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/untitled/main.qml"));
    viewer.showExpanded();

    return app.exec();
}
[/CODE]

___main.qml___
[CODE]
import QtQuick 2.0
import OCUUI 1.0

Rectangle {
    width: 360
    height: 360
    Text {
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }

    SubClass
    {
       functionWhat:
       [
           DummyClass
           {
              lat: "2"
              lon: "3"
           }
       ]
    }


    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
}

[/CODE]

Please help.
Regards,
Anisha Kaul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131112/45d65526/attachment.html>


More information about the Interest mailing list