Results 1 to 11 of 11

Thread: Image showing

  1. #1
    Join Date
    May 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Image showing

    Hi everybody,

    I have following scenerio...

    show image
    wait for some milisecond say 500 ms
    again show image
    wait for some milisecond say 500 ms
    again show image
    ...

    I m using QT-3.1 on Fedora Linux and written following code for showing image on QT Widget.

    fm->setPaletteBackgroundPixmap(QPixmap("sample1.jpg") );
    QApplication::eventLoop()->processEvents(QEventLoop::AllEvents, 100);
    usleep(500);
    fm->setPaletteBackgroundPixmap(QPixmap("sample2.jpg") );
    QApplication::eventLoop()->processEvents(QEventLoop::AllEvents, 100);
    usleep(500);
    fm->setPaletteBackgroundPixmap(QPixmap("sample3.jpg") );
    QApplication::eventLoop()->processEvents(QEventLoop::AllEvents, 100);
    usleep(500);

    Its working ok, but after say some hours, or some days application stucks on processEvents and won't work until i restart the appl or reboot the machine.


    How could i resolve this issue? My application needs to work 24*7.

    Hope everybody got my problem.

    Thanks in advance.

    -Niranjan.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Image showing

    EDIT:
    wont it be better to connect a timer to a slot that show the image every 500ms?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Image showing

    Thanks for your reply.

    I tried with QTimer including following code in form1.ui.h .

    void frmMain::timerSlot()
    {
    fm->setPaletteBackgroundPixmap(QPixmap(objGB.imgName) );
    }

    and called by slot in the function like included in class clsGB
    void clsGB::showScr()
    {
    QTimer::singleShot(500,fm,SLOT(timerSlot()));
    }


    and in the main.cpp i called like
    class clsGB objGB.
    objGB.imgName="sample1.jpg"
    objGB.showScr();
    objGB.imgName="sample2.jpg"
    objGB.showScr();
    objGB.imgName="sample3.jpg"
    objGB.showScr();
    objGB.imgName="sample4.jpg"
    objGB.showScr();
    ............

    It will directly show sample4.jpg. I want like, show sample1.jpg then wait for 500 ms tyhen show sample2.jpg..... etc.


    Is anything other than QTimer or can i write different code for showing image timerslot.

    Thanks in advance

    -Niranjan

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Angry Re: Image showing

    I don't quite understand what it is you have written but the following code should show another image every 500 ms:
    Qt Code:
    1. //in frmMain.h you add:
    2. int m_iImage;
    3.  
    4. //in the constructor you add:
    5. m_iImiage = 1;
    6.  
    7. //and then in your slot:
    8. void frmMain::timerSlot()
    9. {
    10. QString strImageName;
    11.  
    12. switch(m_iImage)
    13. {
    14. case 1: strImageName = "sample1.jpg"
    15. break;
    16. case 2: strImageName = "sample2.jpg"
    17. break;
    18. case 3: strImageName = "sample3.jpg"
    19. break;
    20. case 4: strImageName = "sample4.jpg"
    21. break;
    22. case 5: strImageName = "sample5.jpg"
    23. m_iImage = 0;
    24. break;
    25. }
    26. fm->setPaletteBackgroundPixmap(QPixmap(strImageName ) );
    27. m_iImage++;
    28. }
    To copy to clipboard, switch view to plain text mode 

    This is just variant of doing this, there may be others too.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    May 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Image showing

    Hi,

    Thanks for your reply. Your idea is correct if i don't use singleshot QTimer.
    But in my scenerio, i want to use singleshot timer.

    I written your code in the timerslot and called slot like:
    QTimer *t = new QTimer(fm);
    connect( t, SIGNAL(timeout()), SLOT(timerSlot()) );
    t->start( 500, false );


    Its working fine and i can see images after 500 ms. But actually in my case, i want to use singleShot timer, because its not fixed when i want to show specfic image, its depends on specific event. Like following:


    The main objective in my case is, Image should stay on widget for some interval on perticular event. If any other event occurs then again call image function show other image and wait..

    Algorithm for the problem:

    -------EVENT STARTS---------
    show image
    wait for 500 ms
    -------EVENT COMPLETED-----







    I Hope, you are getting my problem.


    -Niranjan.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Image showing

    Well, then install an event filter, and set the timer interval for each event as you want.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    May 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Image showing

    Hi,

    Thanks for your reply.

    Can you give me sample code, to do this? Let me give one example so that you can understand my scenerio.

    /////////////////main.cpp file start///////////////////////////////////////////////////////////////////////
    #include <qapplication.h>
    #include "form1.h"
    #include "AxSample.h"
    #include <qeventloop.h>
    #include <qsplashscreen.h>
    #include <qpixmap.h>
    class Form1 *fm;
    class AxSample objGB;
    int main( int argc, char ** argv )
    {
    QApplication a( argc, argv );
    Form1 w;
    fm=&w;
    w.show();
    objGB.imgName="sample1.jpg";
    objGB.scrFormat();
    objGB.imgName="sample2.jpg";
    objGB.scrFormat();
    objGB.imgName="sample3.jpg";
    objGB.scrFormat();
    objGB.imgName="sample4.jpg";;
    objGB.scrFormat();
    objGB.imgName="sample5.jpg";
    objGB.scrFormat();
    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    return a.exec();
    }
    ////////////////////main.cpp file end//////////////////////////////////////////////////////////////////////////////



    //////////////AxSample.cpp start/////////////////////////////////////////////////////////////////////////
    #include "form1.h"
    #include "AxSample.h"
    #include <qtimer.h>
    #include <semaphore.h>
    #include <signal.h>
    #include <qpixmap.h>
    #include <qdatetime.h>
    extern Form1 *fm;

    AxSample::AxSample()
    {
    }

    AxSample::~AxSample()
    {
    }
    void AxSample::scrFormat()
    {
    QTimer::singleShot(500,fm,SLOT(showImg()));

    }
    //////////////AxSample.cpp end/////////////////////////////////////////////////////////////////////////


    ///////////AxSample.h start////////////////////////////////////////////////////////////////////////////////////////////

    #include <qstring.h>
    #include <qthread.h>
    class AxSample
    {

    public:
    AxSample();
    ~AxSample();
    QString imgName;
    void scrFormat();
    };

    ///////////////AxSample.h end///////////////////////////////////////////////////////////////////////////////////////


    //////////form1.ui.h start////////////////////////////////////////////////////////////////////////////

    #include "form1.h"
    #include "AxSample.h"
    #include <semaphore.h>
    #include <qtimer.h>
    #include <signal.h>
    #include <qsplashscreen.h>
    extern Form1 *fm;
    extern AxSample objGB;
    void Form1::showImg()
    {

    fm->setPaletteBackgroundPixmap(QPixmap(objGB.imgName) );

    }
    //////////////form1.ui.h end///////////////////////////////////////////////////////////////////////////////////////////


    Now If run this example, i can see only sample5.jpg and thats obivious as QTimer::singleshot is asynchronus function. The above is just a sample for scenerio.In actual code, i call scrformat function on different events or states with image name is diffeernt on each state. Now If you look the above code, how can we show sample1.jpg, then wait.. then sample2.jpg then wait....

    I guess i need some blocking or synchronous function so that after showing image & wait 500 sec i can call second scrformat function


    Thank you.

    -Niranjan.

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Image showing

    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    May 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Image showing

    Hi,

    Thanks for the example. From the above my example, how can we make image showing and waiting for some interval .

    Thanks in advance.

    -Niranjan.

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Image showing

    I showed you already, and you can also see the example code for catching events.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    May 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Image showing

    Hi,

    Thanks for your reply.

    Actually my problem is not about catching events. I already catched the events. Only problem is how to display image and wait. I tried several ways like:

    1st way i tried is:::

    //To display image on widget
    void frmMain::showImage()
    {
    fm->setPaletteBackgroundPixmap(QPixmap(imgName));
    QApplication::eventLoop()->processEvents(QEventLoop::AllEvents, 100);
    usleep(500);
    }

    //As new states comes , it will come in this function to show image and do work of state
    void frmMain::nextState(QString id)
    {
    if(id=="A")
    {
    //show image of state A
    imgName=sample1.jpg;
    showImage();
    ...........
    }
    else if(id=="B")
    {
    //show image of state B
    imgName=sample2.jpg;
    showImage();
    .........
    }

    }

    ////////////////main.cpp//////////////////////////////////////
    .......
    ...
    fm->nextState("A");
    fm->nextState("B");
    .....
    ////////////////////////////////////////////////


    In above now, it workd fine, i can see sample1.jpg,then wait for 500 ms, then sample2.jpg and so on. but sometimes it stucks on QApplication.


    2nd way i tried is using QTimer like:::::::::::


    void frmMain::showImage()
    {
    fm->setPaletteBackgroundPixmap(QPixmap(imgName));

    }

    void frmMain::nextState(QString id)
    {
    if(id=="A")
    {
    //show image of state A
    imgName=sample1.jpg;
    QTimer::singleShot(500,fm,SLOT(showImage()));
    }
    else if(id=="B")
    {
    //show image of state B
    imgName=sample2.jpg;
    QTimer::singleShot(500,fm,SLOT(showImage()));
    }

    }

    ////////////////main.cpp//////////////////////////////////////
    fm->nextState("A");
    fm->nextState("B");
    .....
    ////////////////////////////////////////////////

    In 2nd way, i can see sample2.jpg only and thats obivous as QTimer is asnychronus function.


    If anything other that it please let me know.

    Thank you.

    -Niranjan.

Similar Threads

  1. Image Commander v.1.2
    By piotrek in forum Qt-based Software
    Replies: 0
    Last Post: 20th April 2009, 10:59
  2. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  3. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  4. Explanation to Image Formats
    By sincnarf in forum Qt Programming
    Replies: 13
    Last Post: 6th July 2007, 17:02
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.