PDA

View Full Version : QProgreesDialog updating from within threadable function



Astrologer
3rd May 2010, 08:45
Hi there. I have got a question for you, guys, which I really would like you to help me with.
I have got a function with QString parameter and within the function long-time procedures take place. I execute this function with QFuture but I would like for the progress of operation to be indicated. For example I can declare the variable inside the function and which varies between 0 and 100. How can I arrange it and bind to QProgressDialog? Here goes the snippet:



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(this->ui->test_button, SIGNAL(clicked()), SLOT(call_algorithm()));
}

void MainWindow::call_algorithm()
{
QFuture<void> future = QtConcurrent::run(algorithm, this->ui->jpg_name_edit->text());
}

void algorithm(QString image_name)
{
//some code here =)
}

borisbn
3rd May 2010, 14:19
In QtConcurent functions you can use either static functions ( like your algorythm ) or your class's member function, where you can emit a signal to show the progress of computations. See binding section in QtConcurent docs

Astrologer
3rd May 2010, 14:30
I have solved that. Thanks anyway.

wladek
9th August 2010, 15:07
Hi Astrologer,

Could you post an example with the solution you found and adopted?

Thanks,
Wladek