Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to display image in directory?
Forum Updated to NodeBB v4.3 + New Features

How to display image in directory?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.8k Views 1 Watching
  • 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 Offline
    S Offline
    sanda199
    wrote on last edited by
    #1

    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
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

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

      to

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sanda199
        wrote on last edited by
        #3

        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
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          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
          0
          • S Offline
            S Offline
            sanda199
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sanda199
              wrote on last edited by
              #6

              Still cannot :(

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sanda199
                wrote on last edited by
                #7

                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
                0
                • Q Offline
                  Q Offline
                  QMartin
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved