Results 1 to 5 of 5

Thread: QLabel + timers

  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QLabel + timers

    So im making a picture loop but seem to be a little stuck
    in main
    Qt Code:
    1. sClientz2_300_300Data = _myParse->getClientz2_300_300();
    2.  
    3. z2_300_300 = new QLabel(this);
    4. z2s1_Iterator = new QStringListIterator(sClientz2_300_300Data);
    5. z2_300_300->setGeometry(QRect(781,34,475,360));
    6. QTimer::singleShot(0,this, SLOT(startZ2S1()));
    To copy to clipboard, switch view to plain text mode 

    startZ2S1()
    Qt Code:
    1. if(z2s1_Iterator->hasNext())
    2. {
    3. z2_300_300->clear();
    4. z2_300_300->setPixmap(QPixmap("/ttm/images/" + z2s1_Iterator->next()));
    5. z2_300_300->show();
    6. }
    7. if(!z2s1_Iterator->hasNext())
    8. {
    9. z2s1_Iterator->toFront();
    10. }
    11. emit doneZ2S1();
    To copy to clipboard, switch view to plain text mode 

    the problem i am having is getting this to display the first one only and dont display the next one untill this function is called again

    how would i be able to modify my code to do the above?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QLabel + timers

    Seems obvious enough... don't use a single shot timer if you want more than one shot. It is all in the QTimer details.

  3. #3
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QLabel + timers

    Thanks so much

  4. #4
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QLabel + timers

    so the fallowing code seems to be missing 1 of the strings in the list

    From Debugger:
    Qt Code:
    1. sClientz2_300_300Data <2 items> QStringList
    2. [0] "fb70a926de17ed214dcbe1edd64c2d96.png" QString
    3. [1] "cd3eb7c9403913bf59b414dff8f64d54.png" QString
    To copy to clipboard, switch view to plain text mode 

    so the stringlist sClientz2_300_300Data has 2 items 0,1 but when the following is executed

    in main()
    Qt Code:
    1. z2_300_300 = new QLabel(this);
    2. timerZ2S1 = new QTimer(this);
    3. z2s1_Iterator = new QStringListIterator(sClientz2_300_300Data);
    4. z2_300_300->setGeometry(QRect(781,34,475,360));
    5. connect(timerZ2S1, SIGNAL(timeout()), this, SLOT(startZ2S1()));
    6. timerZ2S1->start(4000);
    To copy to clipboard, switch view to plain text mode 

    in startZ2S1()
    Qt Code:
    1. if(z2s1_Iterator->hasNext())
    2. {
    3. z2_300_300->clear();
    4. //QPixmap *pixmap = new QPixmap("/ttm/images/" + z2s1_Iterator->next());
    5. QString pixpath = "/ttm/images/" + z2s1_Iterator->next();
    6. z2_300_300->setPixmap(QPixmap(pixpath));
    7. }
    8. if(!z2s1_Iterator->hasNext())
    9. {
    10. z2s1_Iterator->toFront();
    11. }
    To copy to clipboard, switch view to plain text mode 

    when the above code is executed it skips item 0 and goes to item 1 and loops it every time timeout() is called

    where am i going wrong ?

  5. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel + timers

    It should work, unless you're doing something wrong somewhere else which you're not showing here.

    Create a compilable example of the issue if you can.
    I can bet you'll realize your mistake when preparing the example

Similar Threads

  1. Multiple timers in single Application
    By Qt Coder in forum Qt Programming
    Replies: 47
    Last Post: 5th October 2012, 13:23
  2. how to use Multiple timers?
    By qtlinuxnewbie in forum Newbie
    Replies: 8
    Last Post: 21st September 2012, 09:01
  3. Timers seemingly getting stuck.
    By MarkSimon in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2010, 12:30
  4. Replies: 1
    Last Post: 29th September 2009, 19:44
  5. How to cleanup timers properly?
    By jpn in forum Qt Programming
    Replies: 7
    Last Post: 6th July 2006, 17:52

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.