[Qt-interest] progress bar doesn't get reset

Yifei Li yifli at mtu.edu
Sun Aug 21 20:43:39 CEST 2011


This minimal example demonstrates the problem. Any idea how to fix the problem? Thanks

#include <QtGui/QApplication>
#include <QMainWindow>
#include <QProgressBar>
#include <QStatusBar>
#include <QFuture>
#include <QFutureWatcher>
#include <QtConcurrentRun>

void spin()
{
    int v = 0;
    for(int i =0; i < 100000; i++)
        ++v;
}


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QMainWindow w;
    QProgressBar *bar = new QProgressBar(&w);
    w.statusBar()->addWidget(bar);

    QFutureWatcher<void> futureWatcher;
    QObject::connect(&futureWatcher, SIGNAL(finished()), bar, SLOT(reset()));
    QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), bar, SLOT(setRange(int,int)));
    QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), bar, SLOT(setValue(int)));

    futureWatcher.setFuture(QtConcurrent::run(spin));

    futureWatcher.waitForFinished();

    w.show();

    return a.exec();
}

Yifei




More information about the Qt-interest-old mailing list