PDA

View Full Version : Implementing threads...



Abc
6th June 2008, 08:16
Hi,
I am making an external process call in QT and trying to compile a file. I want to show the progress of the process either using a progress dialog or just a message box. In my compile() function where I make the call to the external process, I have written it like




QProgressDialog progressDialog(this);

progressDialog.setCancelButtonText(tr("&Cancel"));

progressDialog.setRange(0, fname.size());

progressDialog.setWindowTitle(tr("Compile"));



progressDialog.show();



for (int i = 0; i < fname.size(); ++i) {

progressDialog.setLabelText(tr("Compiling the current file..."));

progressBar.setValue(i);

}


This works fine in windows i.e. the progress dialog is visible when the compile is in progress but this does not show the progress bar in Linux. Please let me know what the possible error could be and how to rectify.

marcel
6th June 2008, 09:17
A non-finishing progress bar is better in this case... Unless the external process notifies you in some way of the compile progress there's no way to know.

What you did there doesn't make any sense... You are just killing the event loop with that for loop, especially if the file is very big.

Therefore try with a non finishing progress bar and you're set.

triperzonak
6th June 2008, 10:02
A non-finishing progress bar is better in this case...

what do you mean by non-fishing?

Abc
6th June 2008, 10:03
Please let me know what you mean by a non-finishing progress bar.

marcel
6th June 2008, 10:04
I mean a QProgressBar where minimum value = maximum value = 0.

marcel
6th June 2008, 10:05
I mean a progress bar that doesn't fish :)
what do you mean by non-fishing?

Abc
7th June 2008, 06:26
I tried the non-finishing progress bar but it's just not showing in Linux.
I am trying to have the progress bar in the status bar depicting the progress of the compile process. But I am not able to view this non-finishing progress bar when compile button is hit. The same thing is working in Windows but not in Linux.

Conel
12th June 2008, 08:41
It looks like paint events for progress bar are cached and are not processed because system is busy with other task (compiling), that's why you don't see progress bar.

You can try to invoke method repaint() or QApplication::flush() or QApplication::processEvents() like:

progressBar.setValue(i);
progressBar.repaint();
QApplication::flush();//this line is probably not necessary

See Qt help for QCoreApplication::flush() method.