Results 1 to 3 of 3

Thread: Qt Signal only emit once? (Signal & Slot problem)

  1. #1
    Join Date
    May 2011
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Post Qt Signal only emit once? (Signal & Slot problem)

    I was testing on Signal and slot based on QGraphicsScene and also QPropertyAnimation.
    Basically I was trying to create a continuous loop of animation using signal and slot.
    I present my code in a simple pseudo code:

    Qt Code:
    1. class PictureItem
    2. {
    3. void animate()
    4. {
    5. QPropertyAnimation ani = new QPropertyAnimation
    6. //animation settings eg. duration, setStartValue, setEndValue
    7. //destroys the animation QAbstractAnimation::DeleteWhenStopped
    8. connect(ani, SIGNAL(destroyed()),this, SLOT(deleteLater))
    9. }
    10. }
    11.  
    12. class Widget
    13. {
    14. constructor
    15. {
    16. sets the QGraphicsScene
    17. sets the QGraphicsView
    18. initPic()
    19. connect(item, SIGNAL(destroyed()),this,SLOT(ReCreate())
    20. }
    21. void initPic()
    22. {
    23. PictureItem item = new PictureItem(....)
    24. item->animate();
    25. }
    26. void ReCreate()
    27. {
    28. initPic()
    29. }
    30. }
    To copy to clipboard, switch view to plain text mode 
    So when i run it, the animation will play once which is based on my first initPic() and will play once more because of the signal and slot. However for the third time the animation doesn't play anymore. I perform a lot of qDebug testing and found out that the SIGNAL in the void animate() function doesn't emit anymore for the 2nd time. Is it because Qt signal can only be emitted once?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qt Signal only emit once? (Signal & Slot problem)

    Your code does not work because
    Qt Code:
    1. connect(item, SIGNAL(destroyed()),this,SLOT(ReCreate())
    To copy to clipboard, switch view to plain text mode 
    is at the wrong place. You have to put in inside the initPic method.

  3. #3
    Join Date
    May 2011
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Qt Signal only emit once? (Signal & Slot problem)

    Thanks a lot. It works now.

Similar Threads

  1. SIGNAL and SLOT Problem
    By RHMK in forum Qt Programming
    Replies: 5
    Last Post: 26th December 2010, 13:45
  2. emit signal from a slot?
    By ask8y@yahoo.com in forum Qt Programming
    Replies: 9
    Last Post: 11th June 2010, 21:18
  3. Signal and Slot Problem
    By waynew in forum Qt Programming
    Replies: 3
    Last Post: 5th June 2010, 11:49
  4. signal / slot problem
    By franco.amato in forum Newbie
    Replies: 13
    Last Post: 8th December 2009, 19:10
  5. problem with signal/slot
    By ihoss in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 23:59

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.