Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qlist declaration
Forum Updated to NodeBB v4.3 + New Features

Qlist declaration

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    Javeria
    wrote on last edited by
    #1

    I have made this object class, but i cant use it in the QList, it gives access to private member issue :
    @#ifndef BOX_H
    #define BOX_H
    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/imgproc/imgproc.hpp"

    #include <iostream>

    using namespace cv;
    using namespace std;

    #include <QObject>

    class Box:public QObject
    {
    Q_OBJECT
    public:
    void Set_id(int x);
    void Set_uitype(string y);
    void Set_parent(int x);
    void Set_position(string y);
    void Set_coordinates(Rect x);
    string get_uitype();
    int get_id();
    int get_parent();
    string get_position();
    Rect get_coordiantes();
    int id;
    string ui_type;
    int parent;
    string position;
    Rect coordinates;
    };

    #endif // BOX_H
    @

    1 Reply Last reply
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      QList is copying the objects you insert into it, but you can't copy QObjets (any instance of the class derived from QObject) look in documentation "here":http://doc.qt.io/qt-5/qobject.html#Q_DISABLE_COPY
      To solve your issue you can create a QList that contains pointers, so must use a QList<Box*>

      https://forum.qt.io/category/41/romanian

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Javeria
        wrote on last edited by
        #3

        But i cant even do that if i use c++ vectors, and i have tried to use pointers but it doesnt save the right values of the object' s members

        1 Reply Last reply
        0
        • ZlatomirZ Offline
          ZlatomirZ Offline
          Zlatomir
          wrote on last edited by
          #4

          std::vector also stores a copy of your data, so it's the same issue.
          If you use pointers and got wrong values it might be that the object get de-allocated before you try to get the values, do you allocate the memory on heap?

          https://forum.qt.io/category/41/romanian

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Javeria
            wrote on last edited by
            #5

            No I dint do that, how should I do it?

            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