Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Display image on screen using qLabel
Forum Updated to NodeBB v4.3 + New Features

Display image on screen using qLabel

Scheduled Pinned Locked Moved Mobile and Embedded
11 Posts 5 Posters 3.0k Views 4 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.
  • Awadhesh MauryaA Offline
    Awadhesh MauryaA Offline
    Awadhesh Maurya
    wrote on last edited by
    #1

    Hi,
    I want to display an image to screen, but It is not working. My code is:

    #include <QtGui/QApplication>
    #include <QLabel>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QPixmap pm("tiger.jpg");
    QLabel lbl;
    lbl.setPixmap(pm);
    lbl.showFullScreen();

    return a.exec();
    }

    Actually I have tried many ways to display, all were fail.
    Please let me know about it.

    Thanks
    Awadhesh

    francescmmF 1 Reply Last reply
    0
    • Awadhesh MauryaA Awadhesh Maurya

      Hi,
      I want to display an image to screen, but It is not working. My code is:

      #include <QtGui/QApplication>
      #include <QLabel>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);

      QPixmap pm("tiger.jpg");
      QLabel lbl;
      lbl.setPixmap(pm);
      lbl.showFullScreen();

      return a.exec();
      }

      Actually I have tried many ways to display, all were fail.
      Please let me know about it.

      Thanks
      Awadhesh

      francescmmF Offline
      francescmmF Offline
      francescmm
      wrote on last edited by
      #2

      @Awadhesh-Maurya
      When you load an image external to the resources file, the image needs to be in the same folder than the executable. Do you have it placed there?

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        You should make sure your path is correct. Also, you should not base your path on current dir (like you are now), because it can change outside of your application (somebody can run the app from a different folder using the command line or a link). It is better to use QCoreApplication::applicationDirPath() as the base path.

        (Z(:^

        Awadhesh MauryaA 1 Reply Last reply
        0
        • sierdzioS sierdzio

          You should make sure your path is correct. Also, you should not base your path on current dir (like you are now), because it can change outside of your application (somebody can run the app from a different folder using the command line or a link). It is better to use QCoreApplication::applicationDirPath() as the base path.

          Awadhesh MauryaA Offline
          Awadhesh MauryaA Offline
          Awadhesh Maurya
          wrote on last edited by
          #4

          @sierdzio
          I replace QPixmap pm("tiger.jpg"); with QPixmap pm("/root/images/tiger.jpg");
          but I am getting same, screen is white.
          tiger.jpg is 800x480 same as lcd used.

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @Awadhesh-Maurya

            1. What version of Qt are you using?
            2. What platform are you using?

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            Awadhesh MauryaA 1 Reply Last reply
            0
            • JKSHJ JKSH

              @Awadhesh-Maurya

              1. What version of Qt are you using?
              2. What platform are you using?
              Awadhesh MauryaA Offline
              Awadhesh MauryaA Offline
              Awadhesh Maurya
              wrote on last edited by
              #6

              @JKSH
              Its 4.8.6 and linux-3.14

              1 Reply Last reply
              0
              • Awadhesh MauryaA Offline
                Awadhesh MauryaA Offline
                Awadhesh Maurya
                wrote on last edited by
                #7

                Hi,
                I am using Linux3.14 with buildroot system on Renesas RSKRZA1H board. I have build qt 4.8.6 with example and free license option in menuconfig.
                I have checked that any image is not displaying using qt in qt example also like icons example.

                Please let me know.

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by JKSH
                  #8

                  Hi @Awadhesh-Maurya,

                  I haven't used Qt 4 in a long time. If I remember correctly, you need to make sure that the "image formats" shared libraries are present. For example,

                  • /<dir>/MyExecutable
                  • /<dir>/imageformats/qjpeg4.so

                  Before that though, check that other simpler things are working correctly. If you create a QPushButton, does it get displayed?

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • Awadhesh MauryaA Offline
                    Awadhesh MauryaA Offline
                    Awadhesh Maurya
                    wrote on last edited by
                    #9

                    Thank you JKSH.
                    QPushButton is working and it's icon is just simple rounded rectangle.
                    I qt example(imagescaling) if I select any image, error message is:

                    QDesktopServices::storageLocation 6 not implemented
                    QPixmap::scaleWidth: Pixmap is a null pixmap

                    In icons example error:
                    QPixmap::scaleWidth: Pixmap is a null pixmap

                    Please let me know to solve these.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      Are you by any chance trying to load an image that is on your computer from your device ? If so, copy that image over to your device filesystem beside the application or to a place known to your application.

                      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
                      1
                      • Awadhesh MauryaA Offline
                        Awadhesh MauryaA Offline
                        Awadhesh Maurya
                        wrote on last edited by
                        #11

                        Actually JPEG and PNG packages were not selected in buildroot building. I have selected these and now these are working.

                        Thanks all of you for your support.

                        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