Results 1 to 11 of 11

Thread: system() function and QProgressBar

  1. #1
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up system() function and QProgressBar

    Hi All,

    I am calling c++ system() function to call run my script from command prompt like below,

    system("ant -buildfile fileName"), i want to run progress bar while the system() function is

    running , But if i call system() function one console is opening and running the script. How to

    avoid console while running system() and how to use QProgressBar to display the status of

    script while its running?
    Thanks,
    Rajesh.S

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: system() function and QProgressBar

    Use QProcess instead.

  3. #3
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: system() function and QProgressBar

    I tried QProcess and startDetached("cmd.exe","ant -buildFile FileName")

    to start the process. Its working , but its running the script seperately, and next satement to

    the QProcess is executing before the completion of the process started.

    even i tried start instead of startDetached , start is not working for cmd.exe.

    I tried to call waitForFinished() next to startDetached() method then also its executing next

    statement before finishing the process, how to stop the execution until the process

    completes.

    My Code :

    Qt Code:
    1. proc->startDetached("cmd.exe","ant -buildFile build.xml","D:/anttest");
    2.  
    3. proc->waitForFinished();
    4.  
    5. QMessageBox::information(this,"Success","ant Success","OK");
    To copy to clipboard, switch view to plain text mode 
    Last edited by rajeshs; 2nd June 2008 at 07:43. Reason: alligned properly
    Thanks,
    Rajesh.S

  4. #4
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: system() function and QProgressBar

    I have gone through Qt Docs.

    there its mentioned waitForFinished() should used for NON GUI. How to achieve the same in GUI
    Apps.
    Thanks,
    Rajesh.S

  5. #5
    Join Date
    Jan 2008
    Posts
    25
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: system() function and QProgressBar

    Make a QEventLoop, connect the finished() signal of the QProcess to the quit() slot of the QEventloop, execute the QProcess, and immediately the QEventLoop. This technique will block until your process is really finished.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: system() function and QProgressBar

    As far as I know when you run an application as detatched, you won't receive a finished signal.

  7. #7
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: system() function and QProgressBar

    I tried mapping finished() signal with qeventquit() slot, its stopping the execution but again its not starting even if the process finished.
    Thanks,
    Rajesh.S

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: system() function and QProgressBar

    Notice that QProcess::startDetached() is a static method. Calling non-static methods have no effect on a detached process.
    Last edited by wysota; 2nd June 2008 at 15:22. Reason: spelling error
    J-P Nurmi

  9. #9
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: system() function and QProgressBar

    how to achieve my requirement any suggestion Please ?
    Thanks,
    Rajesh.S

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: system() function and QProgressBar

    Don't start the process as detached. If it doesn't work, it's because you made some mistake.

  11. #11
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: system() function and QProgressBar

    Sorry , I made mistake in start,

    Previously I used

    Wrong Code:

    Qt Code:
    1. QProcess process = new QProcess(this)
    2. process->start("cmd.exe /C ant -buildfile fileName");
    To copy to clipboard, switch view to plain text mode 

    to start the cmd process.

    This is wrong,


    Now i am using

    Correct Code:


    Qt Code:
    1. QProcess process = new QProcess(this)
    2. process->start("cmd /C ant -buildfile fileName") ;
    To copy to clipboard, switch view to plain text mode 

    Now this is working.


    Thank u for ur continuous help.
    Thanks,
    Rajesh.S

Tags for this Thread

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.