PDA

View Full Version : pointer reference confusion



sincnarf
14th October 2007, 13:33
Hello guys I am trying to modify the Image Viewer example of qt so that it gets an image with its constructor. This is wrong... how can I correct this:


ImageViewer::ImageViewer(QImage *image){
.....
QPixmap pixmap = QPixmap::fromImage(*image);
QPixmap pixmap2 = QPixmap::fromImage(&image);
.....
}


The new ImageViewer terminates upon imageviewer show

marcel
14th October 2007, 13:42
Why do you need to pass a QImage pointer pointer?

QPixmap::fromImage takes a const Image&.
So the statement:


QPixmap pixmap = QPixmap::fromImage(*image);

is correct as long as image is a valid pointer.

It probably crashes because the image pointer is null or not valid.
I say the best way is to pass a const QImage& also, since QImage is implicitly shared.