Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qlist returns Size as -1
QtWS25 Last Chance

Qlist returns Size as -1

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmlqlistesri
11 Posts 5 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mathan M
    wrote on 29 Sept 2016, 15:53 last edited by p3c0
    #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.qml

      for (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.

    J 1 Reply Last reply 29 Sept 2016, 16:00
    0
    • M Mathan M
      29 Sept 2016, 15:53

      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.qml

        for (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.

      J Offline
      J Offline
      JohanSolo
      wrote on 29 Sept 2016, 16:00 last edited by
      #2

      @Mathan-M said in Qlist returns Size as -1:

        for (var ii = 0; ii <= varidPortalSearchItemsCount -1 ;ii++)
      

      This looks odd to me: why don't you use

      for ( var ii = 0; ii < varidPortalSearchItemsCount ; ++ii )
      

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mathan M
        wrote on 29 Sept 2016, 16:02 last edited by
        #3

        ok.

        I am accessing the value of Object.

        idPortalSearchItems.results[ii].size

        In the object, just it store only -1 value.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 29 Sept 2016, 16:18 last edited by
          #4

          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.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on 29 Sept 2016, 19:20 last edited by A Former User
            #5

            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";
                    }
                }
            }
            
            1 Reply Last reply
            3
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on 30 Sept 2016, 05:46 last edited by
              #6

              @Mathan-M You should also post other relevant information like what is results ? What does it return ?

              157

              1 Reply Last reply
              1
              • M Offline
                M Offline
                Mathan M
                wrote on 30 Sept 2016, 07:24 last edited by
                #7

                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.

                ? 1 Reply Last reply 30 Sept 2016, 07:36
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on 30 Sept 2016, 07:29 last edited by
                  #8

                  @Mathan-M What is document ? What is its datatype ? What are type,name,owner,size in that document ? Is it a C++ or Javascript object ?

                  157

                  1 Reply Last reply
                  0
                  • M Mathan M
                    30 Sept 2016, 07:24

                    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.

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on 30 Sept 2016, 07:36 last edited by
                    #9

                    Is result of type QList<QObject*>?

                    M 1 Reply Last reply 30 Sept 2016, 10:14
                    0
                    • ? A Former User
                      30 Sept 2016, 07:36

                      Is result of type QList<QObject*>?

                      M Offline
                      M Offline
                      Mathan M
                      wrote on 30 Sept 2016, 10:14 last edited by
                      #10

                      yes, the return type will be Qlist

                      ? 1 Reply Last reply 30 Sept 2016, 10:20
                      0
                      • M Mathan M
                        30 Sept 2016, 10:14

                        yes, the return type will be Qlist

                        ? Offline
                        ? Offline
                        A Former User
                        wrote on 30 Sept 2016, 10:20 last edited by
                        #11

                        @Mathan-M Ok, then have a look at my code above; that works as expected, what's different to your code?

                        1 Reply Last reply
                        0

                        1/11

                        29 Sept 2016, 15:53

                        • Login

                        • Login or register to search.
                        1 out of 11
                        • First post
                          1/11
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved