Important: Please read the Qt Code of Conduct -

I try to use QProcess::startDetached() funtion.

  • I made command work using QProcess.

    curl "" | perl dbpediaPlaceData.txt 'Haeinsa'

    curl bring json value well,but perl command don't work.


    #include <QObject>
    #include <QDebug>
    #include <QProcess>
    #include <memory>
    template<typename... Args> struct SELECT {
        template<typename C, typename R>
        static constexpr auto OVERLOAD_OF( R (C::*pmf)(Args...) ) -> decltype(pmf) {
            return pmf;
      template<typename CommandCallback>
      QProcess* runCommand(QString command, QStringList args,CommandCallback commandCallback)
          qDebug() << "Run command:" << command << " Args:" << args;
          QProcess *process = new QProcess();
          QByteArray cmdBuff;
          auto conn = std::make_shared<QMetaObject::Connection>();
          *conn = QObject::connect(process, SELECT<int>::OVERLOAD_OF(&QProcess::finished),
                  [commandCallback,conn, process] (int exitCode) {
                      qDebug() << "Reading Results";
                      QByteArray buffer;
                             qDebug() << buffer;
                      qDebug() << "Done Reading Results";
         // process->start(command, args);
          //curl \"\""
          //| perl dbpediaPlaceData.txt 'Haeinsa'
         // curl "" | perl dbpediaPlaceData.txt 'Haeinsa'
          QString filename = "/Users/yoshimi/Music/cridb/dbpediaPlaceData/dbpediaPlaceData.txt";
          QString perl_string = QString("perl %1  \"Haeinsa\"").arg(filename);
          process->startDetached(command, QStringList() << "" << " | "
                                 << perl_string);
          return process;


    #include "qt_run_command.h"
    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        QByteArray strReadOut;
        QString filename = "/Users/yoshimi/Music/cridb/dbpediaPlaceData/dbpediaPlaceData.txt";
         QProcess *process = runCommand("curl" , QStringList() <<  "",
                                        [&strReadOut, &process](QString results)
              qDebug() << "Run command results:" << results;
              strReadOut += results;
              delete process;
         qDebug() << "ByteArray" << strReadOut;
        return a.exec();


    original result
    yoshimi~/Music/cridb/dbpediaPlaceData$ curl "" | perl dbpediaPlaceData.txt 'Haeinsa'


  • @darongyi
    It's difficult to tell what you are trying to do, but it is most unlikely that using startDetached() instead of start() will make any difference to whatever your problem is, and may well make it worse.

    What is the relevance of startDetached() to all of this? Why are you trying to use it, what difference from start() are you expecting it to provide?

  • startDetached() function is easy to access one cmd and arguments.

    If i 'm wrong, I want to know solution..

  • @darongyi
    I'm sorry but I don't know what you mean. In QProcess you could use exec() or start() with much the same arguments as startDetached(). You will not be able to pipe in/out from a detached process, so I don't know how you think your start()ed curl process is going to communicate with your startDetach()ed perl process.

    There is nothing you can accomplish here with startDetach() which you cannot accomplish with start() or exec(), and you have no reason to run either of these processes detached. Up to you.

Log in to reply