Problem Displaying image on Android
-
Hello everyone, I'm having problems displaying images on an android device.
I initially used QPixmap and gave the location of the image on my computer drive, but that didn't work (didn't show image on the phone), and then I tried using the resource file with the .qrc. Using the resource file worked, however, I need to be able to change the image as the image will change daily. Is there any code that I can write to change the image in the .qrc file, keeping the same link? Or any alternative methods?As always any help is Greatly Appreciated.
Thank you -
Hi
QRC files are readonly so you cannot write the image back to it.However, you can use
https://doc.qt.io/qt-5/qstandardpaths.html
to find a place where you have to write access and then save it there.
(and load from there ) -
Thank you, I'm not too familiar with QStandardPaths though, so do you know of any other methods, in which I can read and change the file?
Thanks -
@Alfie-Anil
Hi
To save the changed image, you do need a writable folder so not sure there is a better way.
Also its just
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
or similar -
I'm not sure if this is useful information, but there is a python file that does some webscraping and stores the image in the same folder as the qt c++ file. So is there any way that I could get that Image without directly writing the path in QPixmap because I think that the problem arises when I have to specify the path? (p.s sorry about inconvenience)
-
@Alfie-Anil
Hi
Is that py file with the app exe file ?
You can get path of exe with
qDebug() << "App path : " << qApp->applicationDirPath();
and see if that is same folder.
If you can write there , it could be used also. ( i doubt you can write there ) -
@Alfie-Anil said in Problem Displaying image on Android:
Thank you, I'm not too familiar with QStandardPaths though, so do you know of any other methods, in which I can read and change the file?
ThanksHi,
You better learn to use it. On mobile devices you won't be able to write in the folder where your application reside. This is also valid for default installation on desktop environments.