[Interest] QProcess vs popen: bug?

Bob Hood bhood2 at comcast.net
Thu Nov 12 22:33:00 CET 2015


I have an issue with QProcess in Qt 5.5.1 under Linux.  I have the following 
QProcess code to launch a command-line process (also a Qt executable):

     player.process = ProcessPointer(new QProcess(this));
     connect(player.process.data(), &QProcess::readyReadStandardOutput, this, 
&Mediator::slot_read_player_process_stdout);
     connect(player.process.data(), &QProcess::readyReadStandardError, this, 
&Mediator::slot_read_player_process_stderr);
     connect(player.process.data(), static_cast<void 
(QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
                     this, &Mediator::slot_player_process_error);

     player.process->setProgram(player_path);
     player.process->setArguments(args);
     player.process->start(QIODevice::ReadOnly);
     player.process->waitForStarted();

When I run this code, I get...nothing.  No errors, no slots invoked, no 
process running, nothing in the system log.  However, when I run this code 
instead:

     char data[1024];
     QString command = QString("%1 %2").arg(player_path).arg(args.join(" "));
     FILE* fp = popen(command.toLatin1().constData(), "r");
     while(fgets(data, sizeof(data) - 1, fp) != NULL)
         Logger::inst()->log_info(data);

The process starts and functions as expected.

I had a look at the code for QProcess, which seems to be doing standard 
fork/exec launching of the process, whereas, if I'm not mistaken, popen() uses 
the shell to run it.  Is that the only difference here?  Should I be running 
the QProcess version through the shell explicitly then to make it function?

Thanks.



More information about the Interest mailing list