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:
Code:
class PictureItem
{
void animate()
{
QPropertyAnimation ani = new QPropertyAnimation
//animation settings eg. duration, setStartValue, setEndValue
//destroys the animation QAbstractAnimation::DeleteWhenStopped
connect(ani, SIGNAL(destroyed()),this, SLOT(deleteLater))
}
}
class Widget
{
constructor
{
initPic()
connect(item, SIGNAL(destroyed()),this,SLOT(ReCreate())
}
void initPic()
{
PictureItem item = new PictureItem(....)
item->animate();
}
void ReCreate()
{
initPic()
}
}
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?
Re: Qt Signal only emit once? (Signal & Slot problem)
Your code does not work because
Code:
connect(item, SIGNAL(destroyed()),this,SLOT(ReCreate())
is at the wrong place. You have to put in inside the initPic method.
Re: Qt Signal only emit once? (Signal & Slot problem)
Thanks a lot. It works now.