PDA

View Full Version : passing image to other class



zawal
15th September 2009, 14:16
Hello!

I've written a class wich looks like this:



class ImageViewer
{


public:
ImageViewer();
QImage image;

....

}




I would like to use image in another class methods. How to do it??

jano_alex_es
15th September 2009, 14:22
call the variable from the object, like, for instance:


ImageViewer* myImage = new ImageViewer();
...
...
...
...
QImage objImageViewer = myImage->image;

but please note this is a C++ question, no QT question.

zawal
15th September 2009, 17:20
I've got still issue with it

my code looks like this:

first there is a main function where I create ImageViewer instance:



int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ImageViewer imageViewer;
imageViewer.show();
return app.exec();
}


later on there is a class, where is an QImage object created as public:



class ImageViewer
{


public:
ImageViewer();
QImage image;

....

}



and then I've got other class which constructor look like this:



SceneWindow::SceneWindow()

{
QPixmap pixmap=QPixmap::fromImage(imageViewer->image);
...


and compiler output is:

scenewindow.cpp: In constructor `SceneWindow::SceneWindow()':
scenewindow.cpp:10: error: `imageViewer' was not declared in this scope


So shortly:

we create instance of object in main(), this object contains an image and we need to use this image in method from another class.