Hi,
I am new to QT..just started learning the same. I have good understanding of C++.
Just not clear on GUI programming when done with QT.
I have one Dialog where I need to move few widgets based on some calculation. My calculation runs in while loop and moving of widgets is done with the help of timer. Timer is used because I want to show some animated effect while moving widget...
But, this does not work...code snippet is given below..The reason may be while loop inside also runs while timer is running...that causes timer to restart everytime with new widget to move...
Dialog::Dialog(QWidget*parent) :QDialog(parent)
{
QPushButton*push=newQPushButton(this);
connect(push,SIGNAL(clicked()),this,SLOT(moveWidgets()));
timer=newQTimer(this);
....some code for initializing array of widgets and their positions on dialog
setWindowTitle
(tr
("This dialog title"));
}
void Dialog::moveWidgets()
{
while(widget!=null)
{
Widget.doCalculationForitsNewPosition();
move(widget);
widget = getNextWidget();
}
}
void Dialog::move(widget)
{
timer1->start(100);
}
//this is timer update function
voidDialog::updateTimer()
{
//imagine code here which will move widget by one step.
if(widget is moved to final position)
{
timer->stop();
}
}
You can see that move(widget) function starts timer for animating movement of widget. But, move(widget) itself is being run inside while loop and that while loop restarts the timer....hence only last widget moves...
Can anyone suggest me how to use QThread or some other technique to make sure that only after timer is stopped, while loop continues to next widget...?
Thanks