Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved Problem Displaying image on Android

    Mobile and Embedded
    3
    7
    275
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Alfie Anil last edited by

      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

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 )

        1 Reply Last reply Reply Quote 1
        • A
          Alfie Anil last edited by

          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

          mrjj SGaist 2 Replies Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @Alfie Anil last edited by

            @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

            1 Reply Last reply Reply Quote 0
            • A
              Alfie Anil last edited by Alfie Anil

              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)

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @Alfie Anil last edited by mrjj

                @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 )

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion @Alfie Anil last edited by

                  @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?
                  Thanks

                  Hi,

                  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.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post