Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Cannot pass arguments to git process



  • Hi guys, I'm having problem sending arguments to git process under Linux Ubuntu. This is the code

    QProcess process;
    connect(&process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &my_class::onProcessFinished);
    
        const QString git_process_path{"git"};
        process.setWorkingDirectory(repo.location_.path());
        const QByteArray command = prepare_git_command();
        const QStringList list = QStringList() << "config --list";//<<Here, if the arg count is more than one it doesn't work
        process.start(git_process_path, list);
    

    and slot:

    void my_class::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
    {
        const QString output{process.readAllStandardOutput()};
    }
    

    Basically if I do this:

    const QStringList list = QStringList() << "status";//<<Here, if the arg count is one it works
        process.start(git_process_path, list);
    

    Then it works, but as soon as I have more than one argument, for exaple:

    const QStringList list = QStringList() << "config --list";//<<Here, if the arg count is more than one it doesn't work
        process.start(git_process_path, list);
    

    there is no output.
    How to solve it?
    Thanks in advance.



  • That's not the right way to pass multiple arguments.
    Why does it use a QStringList if you pass all the arguments in one string?
    You should do like

    QStringList() << "config"  << "--list"
    


  • That's not the right way to pass multiple arguments.
    Why does it use a QStringList if you pass all the arguments in one string?
    You should do like

    QStringList() << "config"  << "--list"
    

  • Lifetime Qt Champion

    @smallC said in Cannot pass arguments to git process:

    QProcess process;

    Where do you create this object?


Log in to reply