PDA

View Full Version : Passing QImage Pointers to Dialogs



lynchkp
18th November 2010, 19:46
Hey everyone,

I'm trying to pass a QImage pointer to a dialog window I use to open image files. The reasoning for this is to prevent memory leak.

A snippet of code looks like:


OpenDialog::OpenDialog(QWidget *parent, QImage *imageA, QImage *imageB)
: QDialog(parent)
{
qDebug() << imageA;
loadClicked();
}

void OpenDialog::loadClicked()
{
qDebug() << imageA;
}


which is initialized with:


QImage *imageA_display = 0;
QImage *imageB_display = 0;
openDialog = new OpenDialog(this,imageA_display,imageB_display);


This is a small section, but it illustrates the problem... when qDebug is called the first time, it prints out 0x0 since I have it initialized to an null pointer. The program wont compile when loadClicked is introduced ('imageA was not declared in this scope'). Do variables given to the constructor become global variables? If so then how is imageA not in the scope?

Thanks for all the help in advance!!

Timoteo
18th November 2010, 19:56
Constructor parameters are local to the constructor body. You need a member to contain the pointer. You should look into smart pointers...and an entry level book on c++.