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. Jpeg Image not getting displayed
Qt 6.11 is out! See what's new in the release blog

Jpeg Image not getting displayed

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 4.1k Views 2 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.
  • N Offline
    N Offline
    nitks.abhinav
    wrote on last edited by
    #1

    Hi,

    I am having issues in displaying jpeg image, My code first displays the gif image using QMovie.

    The finished signal of movie is connected to slot which should show a jpeg image.

    Below is the sample code, Base is the main GUI thread.

    Note: If I use fbi tool to display image it works fine.

    void Base::displayWelcomeScreen()
    {
        //Start the  presentation (gif)    
        presnLabel.resize(480,350);   //keeping width 350 acc to the gif
        movie.setFileName("/usr/.images/is5RaptorLoading.gif");
        presnLabel.setMovie (&movie);
        movie.start ();
        presnLabel.show();
    }
    /*Slot function*/
    void Base::displaySysInfoScreen()
    {
        //Display the Raptor system information screen
        presnLabel.hide();
        qDebug() << "Main Thread (BASE): Displaying the  system information screen \n";
        //system ("fbi -T 1  /usr/.images/is5RaptorSysInfo.bmp -d /dev/fb0  -noverbose");
        //sleep(5) ;
        //system("killall fbi");
    
        QPixmap pm("usr/.images/is5RaptorSysInfo.jpeg");
         presnLabel.setPixmap(pm);
         presnLabel.show();
        sleep(5) ;
        presnLabel.hide();
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Using sleep is a bad idea.
      It will halt the event loop and might prevent the window from
      showing/painting. Not sure its that but easy to test.

      void Base::displaySysInfoScreen()
      {
      QPixmap pm("usr/.images/is5RaptorSysInfo.jpeg");
      presnLabel.setPixmap(pm);
      presnLabel.show();
      // sleep(5) ;
      // presnLabel.hide();
      }

      and then call void Base::displaySysInfoScreen() directly.

      Does image show ?

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

        Hi,

        Your sleep call blocks the event loop thus your label never gets shown. Use a single shot QTimer if you want to hide your widget after a given delay.

        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
        3
        • N Offline
          N Offline
          nitks.abhinav
          wrote on last edited by
          #4

          I have removed the sleep but still not able to see image, below is the changed code.
          Also changed the slot function to "rcvPresntationFinisedNotif" which is calling displaySysInfoScreen().

          void Base::displaySysInfoScreen()
          {
              //Display the Raptor system information screen
              QPixmap pm("usr/.images/is5RaptorSysInfo.jpeg");
               presnLabel.setPixmap(pm);
               presnLabel.show();
              //sleep(5) ;
              //presnLabel.hide();
          }
          /SLOT fn */
          void Base::rcvPresntationFinisedNotif()
          {
              qDebug()<< "Main Thread (BASE): Received raptor boot presentation finished signal from base thread\n";
              displaySysInfoScreen();
              //displayLsrScreen();
          
              qDebug()<< "Main Thread (BASE): Now starting worker threads , connecting to notif server and watchdog msg queue\n";
              drpThread->start();
              clientThread->start();
          
              //Connect to the server
              clientThread->serverConnect();
          
              //Connect to the message queue in watchdog
              clientThread->watchdogConnect();
          }
          
          jsulmJ 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You are using a relative path so unless the folder is located in the same folder as the application, the file won't be found.

            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
            • N nitks.abhinav

              I have removed the sleep but still not able to see image, below is the changed code.
              Also changed the slot function to "rcvPresntationFinisedNotif" which is calling displaySysInfoScreen().

              void Base::displaySysInfoScreen()
              {
                  //Display the Raptor system information screen
                  QPixmap pm("usr/.images/is5RaptorSysInfo.jpeg");
                   presnLabel.setPixmap(pm);
                   presnLabel.show();
                  //sleep(5) ;
                  //presnLabel.hide();
              }
              /SLOT fn */
              void Base::rcvPresntationFinisedNotif()
              {
                  qDebug()<< "Main Thread (BASE): Received raptor boot presentation finished signal from base thread\n";
                  displaySysInfoScreen();
                  //displayLsrScreen();
              
                  qDebug()<< "Main Thread (BASE): Now starting worker threads , connecting to notif server and watchdog msg queue\n";
                  drpThread->start();
                  clientThread->start();
              
                  //Connect to the server
                  clientThread->serverConnect();
              
                  //Connect to the message queue in watchdog
                  clientThread->watchdogConnect();
              }
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @nitks.abhinav said in Jpeg Image not getting displayed:

              QPixmap pm("usr/.images/is5RaptorSysInfo.jpeg");

              Looks like you forgot / before usr.
              Also: this path is quite unusual, I never saw anybody creating a hidden directory in /usr, why are you doing this? It is against UNIX/Linux file system structure. If you want to put some data globally for your application do it in /usr/share/YOUR_APP_NAME

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • N Offline
                N Offline
                nitks.abhinav
                wrote on last edited by
                #7

                Couple of issues were there , path with missing / and also jpeg plugin was not there, Thank you.

                I have couple of more questions related to this:

                1. Can bmp image be displayed in similar way?
                2. Image is not aligned to the LCD screen, I can see it shifted to both right and up. How to align it?

                Thanks

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  hi
                  1:yes
                  http://doc.qt.io/qt-5/qtimageformats-index.html
                  2: not sure what u see but the label can center it
                  there is a property

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nitks.abhinav
                    wrote on last edited by
                    #9

                    I have used presnLabel.showMaximized(); and it seems to be working fine. Assume it is correct way.

                    mrjjM 1 Reply Last reply
                    0
                    • N nitks.abhinav

                      I have used presnLabel.showMaximized(); and it seems to be working fine. Assume it is correct way.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      yes when you use the label as window it should be fine.

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        nitks.abhinav
                        wrote on last edited by
                        #11

                        Thankyou for all the help!

                        mrjjM 1 Reply Last reply
                        0
                        • N nitks.abhinav

                          Thankyou for all the help!

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @nitks.abhinav
                          Np, happy programming and remember to set as solved

                          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