Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. print c++ data in qml list view
QtWS25 Last Chance

print c++ data in qml list view

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 445 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.
  • T Offline
    T Offline
    taedooly
    wrote on last edited by
    #1

    i want to print c++ custom data class in qml list view by delegate.

    should i make model in c++ and then call it in qml?

    or is there any way call only data in qml??

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What kind of data are you talking about ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        taedooly
        wrote on last edited by taedooly
        #3
        class resource: public QObject
        {
        Q_OBJECT
        
        public:
            resource(QString);
            ~resource();
            Q_INVOKABLE void addLoss(float, float);
            Q_INVOKABLE float getLoss();
            Q_INVOKABLE QString getName();
        
        private:
            QString name;
            QList<float> *Loss;
        };
        

        my data class is above. and i made resource list as bleow

        in main.cpp

            QList<resource*> *resourceArr;
            qDebug()<< "declare resourceArr";
            resourceArr = new QList<resource*>;
            resource *a = new resource("name");
            resourceArr->push_back(a);
        
            QQmlApplicationEngine engine;
            QQmlContext *context = new QQmlContext(engine.rootContext());   // c++ class to qml object
            context->setContextProperty("resourceVec", &resourceArr);
        

        last line gives me an error like "calling a private constructor of class 'QVariant'"
        and also "atemp to use a deleted function"

        what i want is print resourceArray[idx].getName() / resourceArray[idx].getLoss() in my listView.

        problem looks simple but i have a hard time with it..... i'm noob in qt.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You are passing a pointer to the pointer of your QList object. That's wrong.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • T Offline
            T Offline
            taedooly
            wrote on last edited by
            #5

            i Solved this!. it was not matter of pointers, i've misunderstood about QObect.
            thanks

            1 Reply Last reply
            0

            • Login

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