Qlist returns Size as -1
-
Hi,
I am writing the list of portalsearchitems in an xml file. I can extract the info like Title,Owner but the Size returns -1. I need size for computing the space available.
Code Snippet:
main.qmlfor (var ii = 0; ii <= varidPortalSearchItemsCount -1 ;ii++) { vartextJson += '{"title":"'+ idPortalSearchItems.results[ii].title +'" ,"owner":"'+ idPortalSearchItems.results[ii].owner +'" ,"size":"'+ idPortalSearchItems.results[ii].size +'" //Size is just shown as -1 }' + ','; }
Thanks In advance.
-
Hi
should it not be- idPortalSearchItems.results[ii].size() +
as its a function call?
Also, QList cannot return -1 as far as i know.
it returns 0 for empty list. -
Hi!
I was curious if this might be some JavaScript side effect with "size" being some predefined property or something like that. So, I've build a minimal example and no, no problems, works as expected for me. Can you verify that?dataobject.h
#ifndef DATAOBJECT_H #define DATAOBJECT_H #include <QObject> #include <QString> class DataObject : public QObject { Q_OBJECT Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) Q_PROPERTY(int size READ size WRITE setSize NOTIFY sizeChanged) public: explicit DataObject(const QString &t = QString(), int s = 0, QObject *parent = 0); QString title() const { return m_title; } void setTitle(const QString &t) { if (t == m_title) return; m_title = t; emit titleChanged(t); } int size() const { return m_size; } void setSize(int s) { if (s == m_size) return; m_size = s; emit sizeChanged(s); } signals: void titleChanged(QString); void sizeChanged(int); private: QString m_title; int m_size; }; #endif // DATAOBJECT_H
dataobject.cpp
#include "dataobject.h" DataObject::DataObject(const QString &t, int s, QObject *parent) : QObject(parent) , m_title(t) , m_size(s) { }
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QList> #include <QObject> #include <QQmlContext> #include "dataobject.h" int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QList<QObject*> dataList; dataList << new DataObject("Cheyenne", 23); dataList << new DataObject("Greeneville", 42); dataList << new DataObject("Columbia", 666); QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("dataModel", QVariant::fromValue(dataList)); engine.load(QUrl(QLatin1String("qrc:/main.qml"))); return app.exec(); }
main.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") Text { id: txt anchors.fill: parent } Button { id: btn text: "Click me" anchors.bottom: parent.bottom anchors.left: parent.left onClicked: { for (var i=0; i<dataModel.length; ++i) txt.text += dataModel[i].title + " / " + dataModel[i].size + "\n"; } } }
-
Hi p3c0,
The results will back the portalItems information. If the portal consits of document, It will brings the type,name,owner,size and other relevant information and same applies to map like map type,name,owner,size. The object returns from the portal is perfect except the field Size. It just returning -1. I assume, the problem is not with server.
Thanks In advance.
-
Is
result
of typeQList<QObject*>
? -
yes, the return type will be Qlist