Results 1 to 9 of 9

Thread: How To Incorporate Progress Bar In Program

  1. #1
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How To Incorporate Progress Bar In Program

    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

    Qt Code:
    1. *QProcess *P1 =new QProcess(this) ;
    2. s2 << "-steg" << "coded.txt" << "-q" << ui.compressionspinBox->text() << "cleanimage.ppm" << ui.jpeglineEdit ->text() ;
    3. P1->setReadChannelMode( QProcess::MergedChannels );
    4. P1->start(("cjpeg.exe"),s2);
    5. P1->waitForFinished();
    To copy to clipboard, switch view to plain text mode 

    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 .

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Incorporate Progress Bar In Program

    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.

  3. #3
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Incorporate Progress Bar In Program

    Can you send me some small example based on this .

  4. #4
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How To Incorporate Progress Bar In Program

    ******* 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.


    Qt Code:
    1. if(QFile::exists("coded.txt"))
    2. {
    3. s2 << "-steg" << "coded.txt" << "-q" << ui.compressionspinBox->text() << "cleanimage.ppm" << ui.jpeglineEdit ->text() ;
    4. QProcess *_proc;
    5. _proc = new QProcess( this );
    6. _proc->setReadChannelMode( QProcess::MergedChannels );
    7.  
    8. connect( _proc, SIGNAL( readyReadStandardOutput() ), this, SLOT( read()));
    9. connect( _proc, SIGNAL( started() ), QApplication::instance(), SLOT( aboutQt() ) );
    10.  
    11. connect( _proc, SIGNAL( finished(int, QProcess::ExitStatus) ), QCoreApplication::instance(), SLOT( quit() ) );
    12. _proc->start(("cjpeg"),s2);
    To copy to clipboard, switch view to plain text mode 
    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Incorporate Progress Bar In Program

    Quote Originally Posted by deekayt View Post
    ******* 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.

  6. #6
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How To Incorporate Progress Bar In Program

    @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....

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Incorporate Progress Bar In Program

    Quote Originally Posted by hickscorp View Post
    @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".

  8. The following user says thank you to jacek for this useful post:

    deekayt (9th December 2006)

  9. #8
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How To Incorporate Progress Bar In Program

    Quote Originally Posted by jacek View Post
    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.

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Incorporate Progress Bar In Program

    Quote Originally Posted by hickscorp View Post
    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.

Similar Threads

  1. how to embed an existing kde program into Konquerer
    By sephiroth_0 in forum KDE Forum
    Replies: 1
    Last Post: 15th August 2006, 12:21
  2. Release my simple program to other users ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2006, 23:42
  3. Replies: 1
    Last Post: 17th May 2006, 00:23
  4. preparing program for release
    By impeteperry in forum Installation and Deployment
    Replies: 5
    Last Post: 22nd April 2006, 19:30
  5. Enter key causing program to exit
    By welby in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2006, 16:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.