PDA

View Full Version : How To Incorporate Progress Bar In Program



deekayt
30th November 2006, 10:38
I see this facility of using the progress bar in Qt 4
How to use it in the program.

Suppose I have a program as shown by the code below where
in cjpeg.exe is lauched as a separate process. Can I show the progress bar till the time


*QProcess *P1 =new QProcess(this) ;
QStringList s2;
s2 << "-steg" << "coded.txt" << "-q" << ui.compressionspinBox->text() << "cleanimage.ppm" << ui.jpeglineEdit ->text() ;
P1->setReadChannelMode( QProcess::MergedChannels );
P1->start(("cjpeg.exe"),s2);
P1->waitForFinished();

the cjpeg.exe does the work.
Where all do I have to make the changes .I mean in pro file, header file
and will there be some private slot for this .

jacek
30th November 2006, 11:04
First of all you can't use QProcess::waitForFinished() because your application will freeze while cjpeg works.

You can use QProgressDialog with minimum and maximum value set to 0 (i.e. the "busy" indicator mode) and you just have to show it when you successfully start the process and hide it when that process exits --- for this you can connect to QProcess signals.

deekayt
4th December 2006, 11:28
Can you send me some small example based on this .

deekayt
8th December 2006, 08:58
******* MY THREAD REGARDING SIMILAR QUERY SEEMS TO BE MISSING *****

I see this facility of using the progress bar in Qt 4
How to use it in the program.

Suppose I have a program as shown by the code below where
in cjpeg.exe is lauched as a separate process. Can I show the progress bar till the time
the cjpeg.exe does the work.



if(QFile::exists("coded.txt"))
{
QStringList s2;
s2 << "-steg" << "coded.txt" << "-q" << ui.compressionspinBox->text() << "cleanimage.ppm" << ui.jpeglineEdit ->text() ;
QProcess *_proc;
_proc = new QProcess( this );
_proc->setReadChannelMode( QProcess::MergedChannels );

connect( _proc, SIGNAL( readyReadStandardOutput() ), this, SLOT( read()));
connect( _proc, SIGNAL( started() ), QApplication::instance(), SLOT( aboutQt() ) );

connect( _proc, SIGNAL( finished(int, QProcess::ExitStatus) ), QCoreApplication::instance(), SLOT( quit() ) );
_proc->start(("cjpeg"),s2);
Where all do I have to make the changes .I mean in pro file, header file
and will there be some private slot for this .
Can some body give me sample code incorporating the progress bar.

jacek
8th December 2006, 11:14
******* MY THREAD REGARDING SIMILAR QUERY SEEMS TO BE MISSING *****
It seems you just couldn't find it and, please, don't shout.

As I already wrote, you just have to show that progress bar when you successfully start the process and hide it when that process exits. To do this, you have to connect to proper QProcess signals.

hickscorp
8th December 2006, 15:15
@Jacek: Why not starting a custom thread which takes the progress of the process, and "signals" to the progress bar progress slot? I'm not sure if it's doable....

jacek
8th December 2006, 18:40
@Jacek: Why not starting a custom thread which takes the progress of the process, and "signals" to the progress bar progress slot? I'm not sure if it's doable....
The problem is that there is no feedback from that external process, so all you can do is say "i'm busy right now".

hickscorp
20th December 2006, 14:18
The problem is that there is no feedback from that external process, so all you can do is say "i'm busy right now".

Why not checking in a loop the output of the process, eg. the size of the generated file? Or maybe the process doesn't output anything at all.

jacek
20th December 2006, 15:40
Why not checking in a loop the output of the process, eg. the size of the generated file?
It's a good idea, but there are two problems:
cjpeg.exe might write to the output file when after it has done all of the time consuming operations,
you can't determine the size of the resulting JPEG file, so you won't know where 100% is.