Replace image with new QPixmap in QFile
-
I have a QFile which is .jpg image, and it is part of App resources. How can i replace it's image with completely new? New image have a different resolution, but also .jpg.
I tried this:
QFile myFile(resourcePath); QPixmap myPix = QPixmap::fromImage(QImage(resourcePathNew)); myFile.open(QIODevice::WriteOnly); if(!myPix.save(&myFile)) ui->textEdit->append("Pixmap load failed");
QPixmap::save() is failing, something wrong, and i don't understand what exactly. Any advice will be appreciated.
-
@Engelard said in Replace image with new QPixmap in QFile:
Any advice will be appreciated.
check the return values of the functions you call (c basics) and if the pixmap is valid.
-
@Engelard said in Replace image with new QPixmap in QFile:
Any advice will be appreciated.
You may need to understand what the Qt resource system is all about.
I already suggested the same documentation in your other post related to this same topic. -
-
@JonB said in Replace image with new QPixmap in QFile:
Unless @Christian-Ehrlicher tells me otherwise?
No you're right and when he @Engelard would have checked the return value of open() he would already found out it by himself...
-
@Christian-Ehrlicher
He already did! :)if(!myPix.save(&myFile)) ui->textEdit->append("Pixmap load failed");
Well, he should have checked the
open()
first, I agree.But I think his real issue was he didn't know why it was failing :)