PDA

View Full Version : Can QVector hold objects?



N3wb
14th April 2010, 00:30
Maybe I'm just doing something wrong, but when I try to create a QVector that holds a type of objects I get a whole slew of errors. Can a QVector hold objects, like in in standard C++?

aamer4yu
14th April 2010, 05:50
Yes, why not ?
What errors are you getting ? Without knowing the error we cant say anything.

Ginsengelf
14th April 2010, 07:01
Hi, you won't be able to store an object of an QObject derived class because those classes do not implement the = operator. Only assignable classes can be stored in QVector.

Ginsengelf

N3wb
14th April 2010, 14:27
It is a custom class I was wanting to store. You're saying this isn't possible, right?

In a non-Qt C++ program I defined the class as:



class point{
public:
point();
double lX; // Local x&y
double lY;
double gX; // global x&y
double gY;
};

wysota
14th April 2010, 16:02
It should work without problems. What is the first error message you get?

boudie
14th April 2010, 20:27
You have to store them as pointers.

wysota
14th April 2010, 20:29
You have to store them as pointers.

No, he doesn't. They are not derived from QObject.