Results 1 to 2 of 2

Thread: opening a batch file from Qt

  1. #1
    Join Date
    Nov 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default opening a batch file from Qt

    i want to run a bacth file from QT, currently i have code something like given below. i want to run on cmd is somthing like
    startup.bat -arg1=abc -arg2=abc1 -arg2=abc3 -arg4=abc4
    how do i run the batch file with arguments? any help will be appriciated




    Qt Code:
    1. void MainWindow::on_Button_Go_clicked()
    2. {
    3. QProcess cmd;
    4. const QString myProc = "cmd.exe /c startup.bat " + MainWindow::getWorkingConfiguration(); QString sOldPath = QDir::currentPath();
    5. QString myPath= MainWindow::getWorkingDirectory();
    6. QDir::setCurrent( myPath );
    7.  
    8. //Run it!
    9. cmd.startDetached(myProc);
    10. qDebug(myPath.toStdString().c_str());
    11.  
    12. QDir::setCurrent( sOldPath );
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: opening a batch file from Qt

    Your myProc variable is wrong, it contains the program to run and the arguments instead of just the program.

    The "program" argument to any of the QProcess start methods is just the program, arguments get passed using the "arguments" argument.

    Cheers,
    _

Similar Threads

  1. How to ran a batch file script using cmd?
    By kiboi in forum General Programming
    Replies: 3
    Last Post: 6th February 2013, 09:11
  2. QProcess running batch file
    By Vit Stepanek in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2010, 14:23
  3. Replies: 7
    Last Post: 14th June 2010, 02:42
  4. distclean batch file
    By talk2amulya in forum Qt Programming
    Replies: 0
    Last Post: 11th April 2009, 12:19
  5. QProcess problem with windows batch file
    By bood in forum Qt Programming
    Replies: 11
    Last Post: 6th January 2006, 08:08

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.