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. Can't send image to QLabel in Windows environment (it works without problems in Linux)

Can't send image to QLabel in Windows environment (it works without problems in Linux)

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 505 Views
  • 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.
  • H Offline
    H Offline
    Helge1980
    wrote on last edited by
    #1

    Hi!
    I can't output the image to QLabel in a Windows environment.
    I tried it in two ways. The image size is 144 x 88 pixels (~ 3 KB).

    1. using QImage:
    const QString tmb_file = "C:\\Users\\User\\thumbnail.jpg";
    const QImage img = QImage(tmb_file, "JPG");
    const QPixmap pixmap = QPixmap::fromImage(img);
    ui->labelThumb->setPixmap(pixmap);
    
    1. directly via QPixmap:
    const QString tmb_file = "C:\\Users\\User\\thumbnail.jpg";
    const QPixmap pixmap = QPixmap(tmb_file);
    ui->labelThumb->setPixmap(pixmap);
    
    Pl45m4P JonBJ 2 Replies Last reply
    0
    • H Helge1980

      Hi!
      I can't output the image to QLabel in a Windows environment.
      I tried it in two ways. The image size is 144 x 88 pixels (~ 3 KB).

      1. using QImage:
      const QString tmb_file = "C:\\Users\\User\\thumbnail.jpg";
      const QImage img = QImage(tmb_file, "JPG");
      const QPixmap pixmap = QPixmap::fromImage(img);
      ui->labelThumb->setPixmap(pixmap);
      
      1. directly via QPixmap:
      const QString tmb_file = "C:\\Users\\User\\thumbnail.jpg";
      const QPixmap pixmap = QPixmap(tmb_file);
      ui->labelThumb->setPixmap(pixmap);
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @Helge1980 said in Can't send image to QLabel in Windows environment (it works without problems in Linux):

      I can't

      "I cant" is not a proper description of an issue :)

      Try / instead of \\.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      H 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @Helge1980 said in Can't send image to QLabel in Windows environment (it works without problems in Linux):

        I can't

        "I cant" is not a proper description of an issue :)

        Try / instead of \\.

        H Offline
        H Offline
        Helge1980
        wrote on last edited by Helge1980
        #3

        @Pl45m4

        Replacing \ \ with / didn't help

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then check if the file really exists and is readable.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          H 1 Reply Last reply
          3
          • H Helge1980

            Hi!
            I can't output the image to QLabel in a Windows environment.
            I tried it in two ways. The image size is 144 x 88 pixels (~ 3 KB).

            1. using QImage:
            const QString tmb_file = "C:\\Users\\User\\thumbnail.jpg";
            const QImage img = QImage(tmb_file, "JPG");
            const QPixmap pixmap = QPixmap::fromImage(img);
            ui->labelThumb->setPixmap(pixmap);
            
            1. directly via QPixmap:
            const QString tmb_file = "C:\\Users\\User\\thumbnail.jpg";
            const QPixmap pixmap = QPixmap(tmb_file);
            ui->labelThumb->setPixmap(pixmap);
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Helge1980
            As @Christian-Ehrlicher has said. Also, QPixmap(tmb_file) and QPixmap::fromImage(img) will return a pixmap where QPixmap::isNull() == true, and similarly for QImage(tmb_file, "JPG"). You should check for this, both for debugging/because you have a problem and anyway at runtime since you're reading from a file.

            1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Then check if the file really exists and is readable.

              H Offline
              H Offline
              Helge1980
              wrote on last edited by
              #6

              @Christian-Ehrlicher

              Yes, the file exists and is readable

              Pl45m4P 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Did you relocate Qt or similar? Please check if you jpg image plugin is available and check if jpg can be loaded with e.g. QImageReader::supportedFormats()

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                H 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  Did you relocate Qt or similar? Please check if you jpg image plugin is available and check if jpg can be loaded with e.g. QImageReader::supportedFormats()

                  H Offline
                  H Offline
                  Helge1980
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher

                  No, I didn't move the Qt libraries, everything was installed automatically.

                  Indeed, for some reason there is no support for the JPG format:

                  qDebug() << QImageReader::supportedImageFormats();
                  

                  ("bmp", "pbm", "pgm", "png", "ppm", "xbm", "xpm")

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    The jpeg plugin must be in <QTDIR>/plugins/imageformats

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    3
                    • H Helge1980

                      @Christian-Ehrlicher

                      Yes, the file exists and is readable

                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote on last edited by Pl45m4
                      #10

                      Stupid question:
                      Is the labelThumb QLabel visible and enabled in your GUI?

                      @Helge1980 said in Can't send image to QLabel in Windows environment (it works without problems in Linux):

                      ("bmp", "pbm", "pgm", "png", "ppm", "xbm", "xpm")

                      Edit: Ah ok, so no JPG plugin


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      H 1 Reply Last reply
                      0
                      • Pl45m4P Pl45m4

                        Stupid question:
                        Is the labelThumb QLabel visible and enabled in your GUI?

                        @Helge1980 said in Can't send image to QLabel in Windows environment (it works without problems in Linux):

                        ("bmp", "pbm", "pgm", "png", "ppm", "xbm", "xpm")

                        Edit: Ah ok, so no JPG plugin

                        H Offline
                        H Offline
                        Helge1980
                        wrote on last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          Helge1980
                          wrote on last edited by
                          #12

                          I solved the problem by replacing the jpg format with png

                          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