0

I want to execute an .exe file, which was compiled by g++ (or gcc) from a Qt program. I refer to this topic and try to make it run:

// Setup the working directory
QDir::setCurrent("/home/myproject");

// Start the process (uses new working dir)
bool t= myProc.startDetached("./work");
if (t==false) std::cout<< "Error";
else std::cout <<"OK";

but the result I have is always "Error" and there is no change in my screen even if the program "work" is a GUI program. I did it in terminal but in QProcess I can't :(. What am I doing wrong?

4
  • What about adding a .exe to your executable? Commented Apr 19, 2016 at 9:50
  • @AlexisP. I don't see ".exe" in example so I don't add it Commented Apr 19, 2016 at 10:27
  • You have inverted logic there: t is false when there’s an error, not true. Try with an absolute path instead of ./work. The current directory looks broken, it should be an absolute path also, e.g. /home/youruser. Also note that startDetached is a static method and does nothing to myProc, QProcess::startDetached(…) would be the usual syntax (but yours should work, too) Commented Apr 19, 2016 at 11:23
  • @FrankOsterfeld sorry, my mistake. I fixed that. The program worked in terminal but in QProcess it can't run :( Commented Apr 19, 2016 at 13:06

1 Answer 1

1

It's likely a typo issue. Make sure QDir::setCurrent("home/") does return true; if not, directory change failed and you are not in the directory you expect.

Try starting your executbale attached first (use myProc.execute() instead of myProc.startDetached(), and check what happens. This may reveal some errors that you cannot see when started detached. Make sure your program 'work' does not perform any input from stdin.

Sign up to request clarification or add additional context in comments.

3 Comments

it's not my problem. I think it's about QProcess :(
@Nguyễn Chí: please, give some more inputs... difficult to understand what's happening with the fex info you provided.
it's a GUI program, is a sample code of OpenCV library in C++.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.