Important: Please read the Qt Code of Conduct -

Qlist declaration

  • 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
    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

  • 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":
    To solve your issue you can create a QList that contains pointers, so must use a QList<Box*>

  • 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

  • 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?

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

Log in to reply