PDA

View Full Version : QProcess - Git



RegMe
18th May 2016, 18:41
Hi everyone,

I'm trying to use QProcess with Git, I want to clone my repository to create a local copy on my computer using git clone

Typing this line in Terminal
git clone ssh://user@host:port/Template.git works well

But in Qt, I still have a problem

QProcess process;
process.start("git clone ssh://user@host:port/Template.git", QStringList());

if (!process.waitForStarted()) {
qDebug() << "Error : " << process.errorString();
return 1;
}
//process.waitForFinished(-1); // will wait forever until finished

Error console : Error : "No such file or directory"

Any help is very appreciated

d_stranz
18th May 2016, 20:47
Hmmm, how many times has this QProcess question been asked and answered on this forum? From the QProcess::start() docs:


void QProcess::start(const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite)

Starts the given program in a new process, passing the command line arguments in arguments.

In your case this means:



QProcess process;
QStringList arguments;
arguments << "clone" << "ssh://user@host:port/Template.git";
process.start( "git", arguments );


Assuming of course that the git program is on your system's executable search path and that you have permission to execute it.

Lesiok
18th May 2016, 20:50
You are using this version of method QProcess:start : void QProcess::start(const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite). QProcess is looking for file with name
"git clone ssh://user@host:port/Template.git" Of course it fails. Try this :
process.start("git clone ssh://user@host:port/Template.git"); or this
QStringList params;
params << "clone" << "ssh://user@host:port/Template.git";
process.start("git", params);
P.S. d_stranz was faster ;)

RegMe
19th May 2016, 00:34
Thank you for your ansewers;

I have already tried the method 1:
process.start("git clone ssh://user@host:port/Template.git"); // fails

I'll try tomorrow the 2nd :cool:

Lesiok
19th May 2016, 08:54
Remember what d_stranz wrote : Assuming of course that the git program is on your system's executable search path and that you have permission to execute it.

RegMe
19th May 2016, 10:56
The same problem for the 2nd method :
QProcess process;
QStringList arguments;
arguments << "clone" << "ssh://user@host:port/Template.git";
process.start( "git", arguments );


process.start("git clone ssh://user@host:port/Template.git");

if (!process.waitForStarted()) {
qDebug() << "Error : " << process.errorString();
return 1;
}
qDebug() << "No Error ";

process.waitForFinished(-1); // will wait forever until finished


Console output : No Error ===> Process starts OK ??

I have used QProcess with Gerrit without problems. exmple :
process.start("ssh -p port user@host gerrit create-project test") ===> Creates project in Gerrit OK


Assuming of course that the git program is on your system's executable search path and that you have permission to execute it
How can I be sure of it ??
If Gerrit works without pbs ===> Git also works also ??

Lesiok
19th May 2016, 12:00
Simple : open system command line and type git<Enter>.

RegMe
19th May 2016, 12:28
Yes, I have

I Have already used git clone on system command line whitout problem

Qprocess with Gerrit works well

QProcess with Git fails


projectClone = "git clone ssh://user@host:port/Template.git";
process.start(projectClone);

if (!process.waitForStarted()) {
qDebug() << "Error : " << process.errorString();
return 1;
}
qDebug() << "No Error" ;

if(process.waitForFinished())
{
qDebug() << "Error Waiting : " << process.errorString();
return 1;
}

Console output :
No Error
Error Waiting: "Unknown error"

Lesiok
19th May 2016, 14:10
Is exactly the same command working in command line ?
Do it need some sort of interaction ?

RegMe
19th May 2016, 14:32
Is exactly the same command working in command line ? Yes the same :
git clone ssh://user@host:port/Template.git


Do it need some sort of interaction ? No, just the previous command

Cmd line screenshot: 11945

Lesiok
19th May 2016, 14:51
I have no idea :(

RegMe
19th May 2016, 15:00
Hii,

There is no error in the programm

projectClone = "git clone ssh://user@host:port/Template.git";
process.start(projectClone);

if (!process.waitForStarted()) {
qDebug() << "Error : " << process.errorString();
return 1;
}

if(!process.waitForFinished())
{
qDebug() << "Error Waiting : " << process.errorString();
return 1;
}

But, I don't see the project in my directory :(
With cmd line, I see the project

Lesiok
19th May 2016, 16:46
Before process.start() put in code :
qDebug() << QDir::current();

RegMe
19th May 2016, 18:04
Thanks it works