Results 1 to 6 of 6

Thread: QProcess Problem: Program doesnt start

  1. #1
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question QProcess Problem: Program doesnt start

    Hello,

    I want to start a process from my software. Here is the code that I used:
    Qt Code:
    1. bool MainForm::ProcessStart()
    2. {
    3. try
    4. {
    5. QProcess *programProcess = new QProcess();
    6. programProcess>setWorkingDirectory("c:\\");
    7.  
    8. QStringList arguments;
    9. arguments << "-foo " << bar;
    10.  
    11. programProcess>start("c:\\foobar.exe");
    12. return true;
    13. }
    14. catch (int e)
    15. {
    16. return false;
    17. }
    18. }
    19.  
    20. void MainForm::ProgramStart()
    21. {
    22. if (!ProcessStart())
    23. {
    24. QMessageBox::critical(this, QString::fromUtf8("Process foo cannot started!"),
    25. QString::fromUtf8(
    26. "<p>Foobar.exe cannot opened</p>"));
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 

    But the process didnt started. Whats the problem? Where's my wrong?
    Last edited by musaulker; 29th March 2007 at 23:48. Reason: reformatted to look better

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

    Default Re: QProcess Problem: Program doesnt start

    Quote Originally Posted by musaulker View Post
    QProcess *programProcess = new QProcess();
    Better store that pointer in a member variable, so that you can free it later, otherwise you'll get a memory leak.

    Quote Originally Posted by musaulker View Post
    arguments << "-foo " << bar;
    It should be "-foo" not "-foo ". Also you don't use those arguments anywhere.

    Quote Originally Posted by musaulker View Post
    programProcess>start("c:\\foobar.exe");
    Does it start if you enter:
    cd c:\
    C:\foobar.exe
    in cmd.exe?

    Does programProcess emit error() signal?

    Quote Originally Posted by musaulker View Post
    catch (int e)
    {
    return false;
    }
    I wonder what is going to throw that exception. Especially that it's an integer. Are you sure that this is correct?

  3. #3
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess Problem: Program doesnt start

    Quote Originally Posted by jacek View Post
    Better store that pointer in a member variable, so that you can free it later, otherwise you'll get a memory leak.
    Yes, I'll change it.. Thanks

    Quote Originally Posted by jacek View Post
    It should be "-foo" not "-foo ". Also you don't use those arguments anywhere.
    But what if I want to put a space between more than one arguments? (like: foobar.exe -foo bar foofoo)


    Quote Originally Posted by jacek View Post
    Does it start if you enter: in cmd.exe?
    The problem is probably because of escape characters. Sorry about the path. The true path is like:
    Qt Code:
    1. C:\Documents and Settings\Administrator\foobar.exe
    To copy to clipboard, switch view to plain text mode 
    So I must escape them. Anyway it doesnt worked as I escaped. My firewall (Zone-Alarm) gives a security alert saying:
    MySoftware.exe is trying to launch C:\Documents and Settings\Administrator\foobar.exe, or use another program to gain access to privileged resources. Allow or Deny
    I selected Allow but nothing happens. foobar.exe didn't open. I also disable the firewall and try again, nothing changed. Not whats the problem? What do you think?

    Quote Originally Posted by jacek View Post
    Does programProcess emit error() signal?
    the error says: QProcess::FailedToStart. From the documentation this means:
    The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.
    But I know that program exists there, and I can run and use it normally. And also there musnt be a permission problem, I'm logged in as an administrator.

    Quote Originally Posted by jacek View Post
    I wonder what is going to throw that exception. Especially that it's an integer. Are you sure that this is correct?
    Amm In Visual Studio when a write try and press twice Tab button it opens template of try like this:
    Qt Code:
    1. try
    2. {
    3. }
    4. catch (CException* e)
    5. {
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 
    but it gives a compiler error with this code. I've just changed it to int e, it worked I have a C# background but I dont know if this is working proberly or not. Maybe a bad coding. Dont know..
    Is there a try/catch mechanism in QT library?

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

    Default Re: QProcess Problem: Program doesnt start

    Quote Originally Posted by musaulker View Post
    But what if I want to put a space between more than one arguments? (like: foobar.exe -foo bar foofoo)
    You don't have to add spaces, because you pass parameters as a list.
    Qt Code:
    1. parameters << "-foo" << "bar" << "foofoo";
    To copy to clipboard, switch view to plain text mode 
    Spaces are necessary only when you pass program name and parameters as a single string (for example to QProcess::startDetached()).


    Quote Originally Posted by musaulker View Post
    The problem is probably because of escape characters. Sorry about the path. The true path is like:
    C:\Documents and Settings\Administrator\foobar.exe
    You have used the two-parameter version of QProcess::start(), so Qt probably understood it as run program "C:\Documents" with parameters "and" and "Settings\Administrator\foobar.exe".

    Try:
    Qt Code:
    1. programProcess->start( "c:\\...\\foobar.exe", QStringList() );
    2. // or if you want to add some parameters:
    3. programProcess->start( "c:\\...\\foobar.exe", arguments );
    To copy to clipboard, switch view to plain text mode 
    or wrap that path in quotes:
    Qt Code:
    1. programProcess->start( "\"c:\\...\\foobar.exe\"" );
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by musaulker View Post
    but I dont know if this is working proberly or not.
    It's very unlikely that something is going to throw an integer at you. Better remove both try and catch clauses.

    Quote Originally Posted by musaulker View Post
    Is there a try/catch mechanism in QT library?
    Exceptions are part of C++ language, but Qt itself doesn't throw any exceptions.

  5. #5
    Join Date
    Apr 2020
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QProcess Problem: Program doesnt start

    HI i am also getting problem in starting the this is a simple QCreater GUI in which i want to start communication using Qprocess between two applications , i have tried many approaches but stuck at this point.


    I have tried this method please help me if anyone found the solution to this

    process = new QProcess();
    process->setProcessChannelMode(QProcess::SeparateChannels) ;
    process->start("./fifo");


    if (!process->waitForStarted(100))
    qDebug() << " Unable to startn process ::" << process->error() <<" Error msg" << process->errorString();


    the Error i am getting here is : Unable to startn process :: QProcess::ProcessError(FailedToStart) Error msg "execvp: No such file or directory"


    Please help !!

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,722
    Thanks
    260
    Thanked 760 Times in 750 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QProcess Problem: Program doesnt start

    process->start("./fifo");
    Do you actually have a file with execute permissions in your current working directory? Do you know what QtCreator thinks your working directory is? And does it agree with your idea?

    Try replacing "." with the full path to your file and see if that works. And if it does, add a call to QDir::currentPath() so you can understand what QtCreator is thinking.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 05:19
  2. Quoting problem with QProcess
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2006, 12:24
  3. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 14:30
  4. QProcess start automaticaly needed application
    By raphaelf in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 15:11
  5. QProcess problem with windows batch file
    By bood in forum Qt Programming
    Replies: 11
    Last Post: 6th January 2006, 09: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.