PDA

View Full Version : Q3CanvasRectangle table



Ahmad
21st October 2007, 11:36
i want to have a dynamic table of Q3CanvasRectangle elements inside but as this class does not have a constructor with 0 paramter, i cant create a table of these elements cause i should call one of the provided constructors and it is not possible while creating tables of objects.

i also subclassed the Q3CanvasRectangle like this :

Rectangle::Rectangle():Q3CanvasRectangle(0)
{
}

and then i tried to create a table of Rectangle but i always get some moc erros
Rectangle * tabRectangle; //class dynamique
tabRectangle = new Rectangle[a value];

can anyone help me, cause i must have a table of those Q3CanvasRectangles
tnx

wysota
21st October 2007, 12:19
Use a table of pointers to objects instead of table to objects:

Rectangle *tabRectangle[100];
for(int i=0;i<100;i++)
tabRectangle[i] = new Rectangle(...);

Ahmad
21st October 2007, 12:32
tnx but this methode comes to what i had tried before, it does not solve my problem
always moc error messages...

wysota
21st October 2007, 12:33
Moc shouldn't be ran here at all, as QCanvasRectangle doesn't inherit QObject. Can we see the complete definition of your Rectangle class?

Ahmad
21st October 2007, 13:04
i have nothing inside the Rectangle() constructor, i just wanted to create a rectangle with a default constructor, i mean with no param that i could use to create tables of that Q3CanvasRectangle

Clearly , i want to know if it is possible to have a container(list, vector, tables, whatever) of objects that does not provide a default constructor(0 parameter) and i assume that in that case we must call one of the provided constructors while creating our objects. so in my case i cant create for example a table of Q3CanvasRectangles
like this:
Q3CanvasRectangle tabRectangle[8];
or
Q3CanvasRectangle * tabRectangle;
and later
tabRectangle = new Q3CanvasRectangle[8];
// no default constructor for Q3CanvasRectangle
i hope u ve understand my problem tnx for the repiles

wysota
21st October 2007, 15:21
1. For containers the contained type must have a default constructor.
2. Using an array of canvas objects as opposed to array of pointers to canvas objects will likely cause a crash on exit.
3. If moc scans your file, it means you have the Q_OBJECT macro there, so please tell us the error you get and show the content of the file it complains about (note that I was not asking for the constructor code but for the class definition).