Jpeg Image not getting displayed



  • 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();
    }
    

  • Qt Champions 2016

    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 ?


  • Lifetime Qt Champion

    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.



  • 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();
    }
    

  • Lifetime Qt Champion

    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.


  • Moderators

    @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



  • 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


  • Qt Champions 2016

    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



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


  • Qt Champions 2016

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



  • Thankyou for all the help!


  • Qt Champions 2016

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.