Results 1 to 8 of 8

Thread: Implementing threads...

  1. #1
    Join Date
    Jun 2008
    Posts
    22

    Default Implementing threads...

    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


    Qt Code:
    1. QProgressDialog progressDialog(this);
    2.  
    3. progressDialog.setCancelButtonText(tr("&Cancel"));
    4.  
    5. progressDialog.setRange(0, fname.size());
    6.  
    7. progressDialog.setWindowTitle(tr("Compile"));
    8.  
    9.  
    10.  
    11. progressDialog.show();
    12.  
    13.  
    14.  
    15. for (int i = 0; i < fname.size(); ++i) {
    16.  
    17. progressDialog.setLabelText(tr("Compiling the current file..."));
    18.  
    19. progressBar.setValue(i);
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by jpn; 6th June 2008 at 08:44. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing threads...

    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.

  3. #3
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing threads...

    Quote Originally Posted by marcel View Post
    A non-finishing progress bar is better in this case...
    what do you mean by non-fishing?

  4. #4
    Join Date
    Jun 2008
    Posts
    22

    Default Re: Implementing threads...

    Please let me know what you mean by a non-finishing progress bar.

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing threads...

    I mean a QProgressBar where minimum value = maximum value = 0.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing threads...

    I mean a progress bar that doesn't fish
    Quote Originally Posted by triperzonak View Post
    what do you mean by non-fishing?

  7. #7
    Join Date
    Jun 2008
    Posts
    22

    Default Re: Implementing threads...

    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.

  8. #8
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    33
    Thanks
    2
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Implementing threads...

    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:rocessEvents() like:

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

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

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. signal and slot across threads having event loop
    By travis in forum Qt Programming
    Replies: 6
    Last Post: 5th November 2007, 23:56
  3. Once more: Threads in Qt4
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 9th August 2006, 18:35
  4. [QT4] threads, signals, and slots, please help.
    By ucntcme in forum Qt Programming
    Replies: 12
    Last Post: 25th January 2006, 14:23

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.