Qt Forum

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

    How to display image in directory?

    General and Desktop
    3
    8
    3249
    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.
    • S
      sanda199 last edited by

      Hi I am quite new to qt. I wrote a program which display image in label. But at first I put image in build folder of my program. It can display fine. But when I move my image to home folder, it cannot display. My image is at Home folder. I am using ubuntu 11.10. my program is like that
      @
      #include <QtGui/QApplication>
      #include "mainwindow.h"
      #include <QLabel>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      QImage myImage;
      myImage.load(":/Home/1.jpeg");

      QLabel myLabel;
      myLabel.setPixmap(QPixmap::fromImage(myImage));
      
      myLabel.show();
      
      
      return a.exec(&#41;;
      

      }
      @

      If anything wrong, pls kindly tell me. Thanks.

      Edit: please enclose code snippets in @ tags; Andre

      1 Reply Last reply Reply Quote 0
      • Q
        qxoz last edited by

        Maybe change
        @myImage.load(”:/Home/1.jpeg”);@

        to

        @myImage.load(”/home/1.jpeg”);@

        1 Reply Last reply Reply Quote 0
        • S
          sanda199 last edited by

          still cannot :(
          [quote author="qxoz" date="1360298371"]Maybe change
          @myImage.load(”:/Home/1.jpeg”);@

          to

          @myImage.load(”/home/1.jpeg”);@[/quote]

          1 Reply Last reply Reply Quote 0
          • Q
            qxoz last edited by

            Sorry i was wrong.
            In ubuntu as i know home path is /home/username/
            So check the real path of file, it must be something like /home/username/1.jpeg

            1 Reply Last reply Reply Quote 0
            • S
              sanda199 last edited by

              but my image is at home folder. Do i need to put username as well?

              1 Reply Last reply Reply Quote 0
              • S
                sanda199 last edited by

                Still cannot :(

                1 Reply Last reply Reply Quote 0
                • S
                  sanda199 last edited by

                  now i can get it as you said. thanks a lot :)
                  [quote author="qxoz" date="1360303353"]Sorry i was wrong.
                  In ubuntu as i know home path is /home/username/
                  So check the real path of file, it must be something like /home/username/1.jpeg[/quote]

                  1 Reply Last reply Reply Quote 0
                  • Q
                    QMartin last edited by

                    Hello

                    I know this was solved, but you could avoid future problems with images when using "Qt's resources mechanism":http://qt-project.org/doc/qt-4.8/resources.html.

                    bq. The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.

                    Hope this helps a little bit more and takes you one step further :)

                    Regards

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