Does anyone have any ideas about what's going on here?
This is intended (see QThread: QObject). The receiver MainWindow
is in another thread. Since the default connection is AutoConnection
, Qt will use a QueuedConnection
and run the slot animateSave
in the same thread as your MainWindow
object.
However, you shouldn't use QThread
at all. You don't want to do things at the same time, instead, you want something to happen at (or after) a given time. QTimer
is what you want.
MainWindow::MainWindow(QWidget *parent)
{
/* ... */
myTimer = new QTimer(this);
connect(myTimer, SIGNAL(timeout(), this, SLOT(decreaseAlphaOrStop()));
}
void MainWindow::on_Btn_Save_clicked(){
/* .. snip .. */
alpha = 250;
myTimer->start(250);
}
// new slot
void MainWindow::decreaseAlphaOrStop(){
alpha -= 50;
if( alpha < 0){
alpha = 0;
myTimer->stop();
}
animateSave(alpha);
}