Hi guys!
I've got the following situation:
Somewhere in my GUI I start a lengthy computation in my BackgroundImageItem which inherits from QThread:
BackgroundImageItem* back = new BackgroundImageItem(filename);
// let the worker thread work:
back->start();
BackgroundImageItem* back = new BackgroundImageItem(filename);
// let the worker thread work:
back->start();
To copy to clipboard, switch view to plain text mode
to inform the user that the application is working, I have written the following simple self-updating Progressbar:
{
public:
ThreadedProgressBar
(QWidget * parent
) {
this->setGeometry(
(parent->width() - 300)/2,
(parent->height()-30)/2,
300, 30);
this->setTerminationEnabled(true);
this->start();
};
void run()
{
while(true)
{
this->setValue((this->value()+20)%100);
this->update();
this->msleep(100);
}
};
virtual ~ThreadedProgressBar();
};
class ThreadedProgressBar : public QThread, public QProgressBar
{
public:
ThreadedProgressBar(QWidget * parent)
: QProgressBar(parent)
{
this->setGeometry(
(parent->width() - 300)/2,
(parent->height()-30)/2,
300, 30);
this->setTerminationEnabled(true);
this->start();
};
void run()
{
while(true)
{
this->setValue((this->value()+20)%100);
this->update();
this->msleep(100);
}
};
virtual ~ThreadedProgressBar();
};
To copy to clipboard, switch view to plain text mode
What I did then to show this ThreadedProgressbar was:
BackgroundImageItem* back = new BackgroundImageItem(filename);
// let the worker thread work:
back->start();
//start the progressBar,
//note: this->parentWidget() is the main widget of my app
ThreadedProgressBar * pbar = new ThreadedProgressBar(this->parentWidget());
// Join the gui thread with the worker thread
back->wait();
// a thread must be terminated before being deleted
pbar->terminate();
//clean up
delete pbar;
BackgroundImageItem* back = new BackgroundImageItem(filename);
// let the worker thread work:
back->start();
//start the progressBar,
//note: this->parentWidget() is the main widget of my app
ThreadedProgressBar * pbar = new ThreadedProgressBar(this->parentWidget());
// Join the gui thread with the worker thread
back->wait();
// a thread must be terminated before being deleted
pbar->terminate();
//clean up
delete pbar;
To copy to clipboard, switch view to plain text mode
BUT THE PROGRESS BAR DOES NOT SHOW UP !!!!
I'm sure I just did a small mistake!
Thanks for zour help in advance,
best regards,
Olli
Bookmarks