Results 1 to 7 of 7

Thread: Qt 5 QProcess Strange Problem on Windows.

  1. #1
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt 5 QProcess Strange Problem on Windows.

    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:
    Qt Code:
    1. g++ D:\a.cpp -static -o D:\a.exe
    To copy to clipboard, switch view to plain text mode 
    So I write the code following:
    Qt Code:
    1. QProcess *gccCompile=new QProcess(this);
    2. arg<<filePath<<"-static"<<"-o"<<fileInfo.absolutePath()+"/"+fileInfo.completeBaseName()+".exe";
    3. gccCompile->start(gccPath, arg)
    To copy to clipboard, switch view to plain text mode 

    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?

  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: Qt 5 QProcess Strange Problem on Windows.

    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
    Qt Code:
    1. << QFileInfo(fileInfo.dir(), fileInfo.baseName() + ".exe");
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 5 QProcess Strange Problem on Windows.

    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:
    Qt Code:
    1. g++.exe D:/a.cpp -o D:/a.exe
    To copy to clipboard, switch view to plain text mode 

    So I guess this isn't the problem.
    Actually, I tried this cmd in Qt too:
    Qt Code:
    1. QProcess *gccCompile=new QProcess(this);
    2. gccCompile->start("C:\\mingw\\bin\\g++.exe D:/a.cpp -o D:/a.exe");
    To copy to clipboard, switch view to plain text mode 

    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??

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt 5 QProcess Strange Problem on Windows.

    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()?

  5. #5
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 5 QProcess Strange Problem on Windows.

    Quote Originally Posted by ChrisW67 View Post
    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?

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt 5 QProcess Strange Problem on Windows.

    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?

  7. #7
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 5 QProcess Strange Problem on Windows.

    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?

Similar Threads

  1. QFile::remove() strange refresh problem in windows desktop
    By ramazangirgin in forum Qt Programming
    Replies: 6
    Last Post: 8th December 2010, 03:42
  2. Replies: 2
    Last Post: 6th September 2010, 15:22
  3. Strange Behaviour with QProcess, QFileDialog and gdb
    By vratojr in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2010, 12:48
  4. Problem using QProcess on Windows XP
    By shopov in forum Newbie
    Replies: 3
    Last Post: 29th April 2010, 13:28
  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.