qpixmap::scaled: Pixmap is a null pixmap error on RELEASE, but works properly in DEBUG
-
void NoImagenState::cargarImagen() {
QDesktopWidget desk;
QRect screenres = desk.screenGeometry(0);QString selfilter = this->mw->tr("JPEG (*.jpg *.jpeg);; PNG (*.png)"); QString path_name; QFileDialog dialog( this->mw, "Seleccionar Imagen", ".//imagenes//", selfilter); dialog.setFileMode(QFileDialog::ExistingFiles); dialog.setGeometry(QRect(screenres.width()/4,screenres.height() /4,screenres.width()/2,screenres.height()/2)); dialog.show(); if (dialog.exec()) path_name = dialog.selectedFiles()[0]; if (path_name == "") { mw->cambiarEstado(mw->getNoImagenState()); return; } mw->set_imagen_name(path_name); QPixmap pix(path_name); mw->set_imagen_path(path_name); mw->set_imagen(pix); qDebug("hello"); this->mw->ui->imagen->setPixmap(pix.scaledToHeight(this->mw->ui->imagen->height())); mw->cambiarEstado(mw->getImagenCargadaState());
};
Application output in RELEASE:
hello
QPixmap::scaleHeight: Pixmap is a null pixmap
szValue=0Application output in DEBUG:
hello
---------cambiando de estado a IMAGEN CARGADA------------- -
@alberto2
Please alter to following:qDebug() << path_name; QPixmap pix(path_name); qDebug() << pix.isNull();
My guess is (as hinted bu @jsulm): the return value from
path_name = dialog.selectedFiles()[0];
is a relative path, and it is relative to something other than the current working directory, perhaps when you run the Release executable outside of Creator whereas you run the Debug executable from within Creator?I don't know why you have pairs of
/
s in".//imagenes//"
, it's not helpful. You also should not have a relative path here, since you do not know what the current directory will be at runtime. Make an absolute path to wherever this directory is, using QStandardPaths Class, choosing the entry in enum QStandardPaths::StandardLocation which best captures wherever you deploy to.You also should not have
dialog.show(); if (dialog.exec()) path_name = dialog.selectedFiles()[0];
Remove the
dialog.show();
here. -
@JonB
ok! Thanks for your tips. I finally got it to work.
The code was ok afterall, but in the release folder, inside the imageformats folder, some dlls were missing. I overwrote this folder with the one in C:\Qt\5.15.2\msvc2019\plugins\imageformats, and that solved the issue.