Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved print c++ data in qml list view

    Mobile and Embedded
    2
    5
    180
    Loading More Posts
    • 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
      taedooly last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • T
          taedooly last edited by taedooly

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 1
            • T
              taedooly last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post