views:

48

answers:

1

Here is the code:

#include <QtCore/QCoreApplication>
#include <QProcess>
#include <QProcessEnvironment>

int main(int argc, char *argv[])
{
    QProcessEnvironment env;

    // Environment variables required by CGI apps

    env.insert("QUERY_STRING",      url.encodedQuery());
    env.insert("REQUEST_URI",       url.toString());
    env.insert("REQUEST_METHOD",    "GET");
    env.insert("REMOTE_ADDR",       pSocket->peerAddress().toString());

    //==========

    QProcess process;
    process.setProcessEnvironment(env);
    process.start("php-cgi",QProcess::ReadWrite);

    process.write("<?php print_r($_GET); ?>");
    process.closeWriteChannel();

    process.waitForFinished();

    qDebug(process.readAll().data());

    return 0;
}

Qt Creator reports more than 14000 errors. Here is a small sample of them:

In file included from ../QProcess/main.cpp:2:
../QProcess/QProcess:1: error: stray ‘\177’ in program
../QProcess/QProcess:1: error: stray ‘\2’ in program
../QProcess/QProcess:1: error: stray ‘\1’ in program
../QProcess/QProcess:1: error: stray ‘\1’ in program
In file included from ../QProcess/main.cpp:2:
../QProcess/QProcess:1:8: warning: null character(s) ignored
../QProcess/QProcess:1: error: stray ‘\2’ in program
A: 

The problem was that I was including the wrong headers:

#include <QProcess>

...instead of...

#include <QtCore/QProcess>
George Edison
Don't get it. 1. Usually both versions are found, <Bar> and <QtFoo/Bar> (depends on the build system though) 2. Both should work, once found 3. The header is apparently found, otherwise you would get another error message. Or do you have some unrelated file around, also named QProcess?
Frank
@Frank: Ya, that ended up being the problem.
George Edison