PDA

View Full Version : QList



sabeesh
3rd October 2007, 07:40
Hi,
I have a class named as CVideoFrame and I create two constructor like this,

CVideoFrame::CVideoFrame(uint number, const QImage *rgb, const QImage *y, const QImage *u, const QImage *v)
{
qDebug("Enter 1st constructor");
}

and

CVideoFrame::CVideoFrame(const CVideoFrame &f)
{
qDebug("Enter 2nd constructor");
}


and in my program I declare some variables like this,
uint i;
const QImage *rgb, *y, *u, *v;
QList<CVideoFrame> m_VideoFrames;

and CVideoFrame *frame = new CVideoFrame(i, rgb, y, u, v);

at this time the first constructor is created and the message " Enter 1st constructor " is print. But when i try this line
m_VideoFrames.append(*frame);
then the second constructor is work and the message " Enter 1st constructor " is print.

Here I try to append the value to m_VideoFrames. So why the second constructor is work.
Please help me to solve this problem

wysota
3rd October 2007, 08:21
The list creates an element of type CVideoFrame and assigns it the argument of append(). And this is done using the copy constructor.

rajesh
3rd October 2007, 08:28
this happen becouse you added a object in the list not pointer of object, so it is creating a new object and calling default constructor.

you change like this:
QList<CVideoFrame*> m_VideoFrames; // store pointer in list
CVideoFrame *frame = new CVideoFrame(i, rgb, y, u, v);
m_VideoFrames.append(frame); // dont put * here.