Passing QImage to a function
I need to write a function that accept QImage as an input. I declared QImage pointer as
And create a new image and set this pointer as
@QImage img("path to image file");
image = &img;
And I have a function like this
ui->imgLabel->setPixmap(QPixmap::fromImage(*image)); // This line gives an arithmetic exception why?
It compiles without any error, but get an arithmetic exception at ui->imgLabel->setPixmap(QPixmap::fromImage(*image));
Also please let me know the difference between
@somefunction(QImage *image)@ and @somefunction(QImage &image)@
At first sight, your img goes out of scope, so it get destroyed.
You probably also have a warning saying that you are using a pointer to a local variable.
someFunction should use a const QImage& image (especially since you will set your QImage on a label)
QImage * is a pointer to a QImage
QImage & is a reference to a QImage
Hope it helps