Si vous utilisez vraiment des variables d'étendue de fonction, cela ne devrait pas avoir d'importance. Exemple:
class WheelSpinner : public QThread
{
Q_OBJECT;
public:
WheelSpinner(QObject* receiver, const char* slot)
{
connect(this, SIGNAL(valueChanged(int)), receiver, slot,
Qt::DirectConnect);
}
void run()
{
for (int i = 0; i < 100000; ++i)
{
emit (valueChanged(i));
}
}
public signals:
void valueChanged(int value);
};
class ProgressTracker : public QObject
{
Q_OBJECT;
public:
ProgressTracker() { }
public slots:
void updateProgress(int value)
{
// While in this function, "value" will always be the proper
// value corresponding to the signal that was emitted.
if (value == 100000)
{
// This will cause us to quit when the *first thread* that
// emits valueChanged with the value of 100000 gets to this point.
// Of course, other threads may get to this point also before the
// program manages to quit.
QApplication::quit();
}
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
ProgressTracker tracker;
WheelSpinner spinner1(&tracker, SLOT(updateProgress(int )));
WheelSpinner spinner2(&tracker, SLOT(updateProgress(int )));
WheelSpinner spinner3(&tracker, SLOT(updateProgress(int )));
spinner1.run();
spinner2.run();
spinner3.run();
return (app.exec());
}
Donc dans ce cas, vous dites que si le même objet WheelSpinner (disons spinner2) appelle updateProgress pour i, et que l'appel i-1th n'est pas encore terminé, il fonctionnera bien? –
@ trex279: Tout d'abord, avec une connexion directe, si spinner2 appelle updateProgress pour i, il ne continuera pas tant que la fonction updateProgress n'est pas terminée. Cette partie est séquentielle. Si, toutefois, spinner1 s'exécute pour i + 1 alors que spinner2 exécute toujours la même fonction pour i, les deux s'exécuteront correctement. –