PDA

View Full Version : Qt 5 QProcess Strange Problem on Windows.



harinlen
27th June 2013, 05:50
Hello, I'm now working on an IDE written by Qt, But I get some strange stucks now...

I want to compile a cpp file using MinGW. I got the path of g++.exe. I want to execute the command like this:

g++ D:\a.cpp -static -o D:\a.exe
So I write the code following:

QProcess *gccCompile=new QProcess(this);
QStringList arg;
arg<<filePath<<"-static"<<"-o"<<fileInfo.absolutePath()+"/"+fileInfo.completeBaseName()+".exe";
gccCompile->start(gccPath, arg)

All the QStrings in arg are correct, I've been checked by qDebug();
The file compiles successfully, but I find out that there isn't any new exe file in the folder. g++.exe has been launched successfully(I find this by taskmgr).
My friends test this on his Ubuntu 13, he said that there's nothing wrong! This is what actaully shocked me.
What's wrong with my code? I'm using Qt 5.1 Beta, and he is using Qt 5.0. Is this a bug on Qt 5.1 Beta?

anda_skoa
27th June 2013, 10:13
My guess would be that the command has difficulties with / in the filename. Since this is the path separator on Unix it works on Ubuntu.

I would recommend using QFileInfo(QDir, QString) to create the new file path, something like


<< QFileInfo(fileInfo.dir(), fileInfo.baseName() + ".exe");


Cheers,
_

harinlen
27th June 2013, 17:04
Thanks for your quick reply~~I'm very glad to re

I guess this was the problem at first, too. But when I execute the following command in cmd.exe, it really works:


g++.exe D:/a.cpp -o D:/a.exe


So I guess this isn't the problem.
Actually, I tried this cmd in Qt too:


QProcess *gccCompile=new QProcess(this);
QStringList arg;
gccCompile->start("C:\\mingw\\bin\\g++.exe D:/a.cpp -o D:/a.exe");


g++.exe is execute, but there isn't any output info and no exe created. I was really confuse about this. My code is wrong??

ChrisW67
28th June 2013, 00:23
QProcess::start() executes asynchronously, i.e. after returning to the Qt event loop, are you looking for a result immediately after executing start()... it won't be there.
Is QProcess::started() or QProcess::finished() emitted?
Have you looked at the values returned by QProcess::exitCode() and QProcess::exitStatus()?

harinlen
28th June 2013, 12:43
QProcess::start() executes asynchronously, i.e. after returning to the Qt event loop, are you looking for a result immediately after executing start()... it won't be there.
Is QProcess::started() or QProcess::finished() emitted?
Have you looked at the values returned by QProcess::exitCode() and QProcess::exitStatus()?

Thanks a million~~
I know the process has been exit by watching process list in taskmgr. g++.exe has been exit.
exitCode is 5 and exitStatus is Unknown Error. This is what I noticed, but what can I do?

ChrisW67
29th June 2013, 07:13
Be very sure you are testing from the same environment as the running Qt program has. Is the PATH identical? Can g++ find the MingW runtime in that environment?

harinlen
1st July 2013, 02:27
I'm pretty sure.
My friend runs the SAME code which I have, and there is nothing wrong on his machine. The same MinGW, the same configure, the same path, the same OS(Windows 7 Ultimate 64-bit) and the same work path.
The ONLY different between us is my Qt version is 5.1 RC, his is 5.0.2. Is this the problem?