Results 1 to 14 of 14

Thread: QProcess - Git

  1. #1
    Join Date
    Dec 2015
    Posts
    35
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QProcess - Git

    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
    Qt Code:
    1. git clone ssh://user@host:port/Template.git
    To copy to clipboard, switch view to plain text mode 
    works well

    But in Qt, I still have a problem
    Qt Code:
    1. QProcess process;
    2. process.start("git clone ssh://user@host:port/Template.git", QStringList());
    3.  
    4. if (!process.waitForStarted()) {
    5. qDebug() << "Error : " << process.errorString();
    6. return 1;
    7. }
    8. //process.waitForFinished(-1); // will wait forever until finished
    To copy to clipboard, switch view to plain text mode 

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

    Any help is very appreciated

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,318
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QProcess - Git

    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:

    Qt Code:
    1. QProcess process;
    2. QStringList arguments;
    3. arguments << "clone" << "ssh://user@host:port/Template.git";
    4. process.start( "git", arguments );
    To copy to clipboard, switch view to plain text mode 

    Assuming of course that the git program is on your system's executable search path and that you have permission to execute it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    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
    Qt Code:
    1. "git clone ssh://user@host:port/Template.git"
    To copy to clipboard, switch view to plain text mode 
    Of course it fails. Try this :
    Qt Code:
    1. process.start("git clone ssh://user@host:port/Template.git");
    To copy to clipboard, switch view to plain text mode 
    or this
    Qt Code:
    1. QStringList params;
    2. params << "clone" << "ssh://user@host:port/Template.git";
    3. process.start("git", params);
    To copy to clipboard, switch view to plain text mode 
    P.S. d_stranz was faster

  4. #4
    Join Date
    Dec 2015
    Posts
    35
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    Thank you for your ansewers;

    I have already tried the method 1:
    Qt Code:
    1. process.start("git clone ssh://user@host:port/Template.git");
    To copy to clipboard, switch view to plain text mode 
    // fails

    I'll try tomorrow the 2nd

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    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.

  6. #6
    Join Date
    Dec 2015
    Posts
    35
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    The same problem for the 2nd method :
    Qt Code:
    1. QProcess process;
    2. QStringList arguments;
    3. arguments << "clone" << "ssh://user@host:port/Template.git";
    4. process.start( "git", arguments );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. process.start("git clone ssh://user@host:port/Template.git");
    2.  
    3. if (!process.waitForStarted()) {
    4. qDebug() << "Error : " << process.errorString();
    5. return 1;
    6. }
    7. qDebug() << "No Error ";
    8.  
    9. process.waitForFinished(-1); // will wait forever until finished
    To copy to clipboard, switch view to plain text mode 

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

    I have used QProcess with Gerrit without problems. exmple :
    Qt Code:
    1. process.start("ssh -p port user@host gerrit create-project test")
    To copy to clipboard, switch view to plain text mode 
    ===> 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 ??

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    Simple : open system command line and type git<Enter>.

  8. #8
    Join Date
    Dec 2015
    Posts
    35
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    Yes, I have

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

    Qprocess with Gerrit works well

    QProcess with Git fails
    Qt Code:
    1. projectClone = "git clone ssh://user@host:port/Template.git";
    2. process.start(projectClone);
    3.  
    4. if (!process.waitForStarted()) {
    5. qDebug() << "Error : " << process.errorString();
    6. return 1;
    7. }
    8. qDebug() << "No Error" ;
    9.  
    10. if(process.waitForFinished())
    11. {
    12. qDebug() << "Error Waiting : " << process.errorString();
    13. return 1;
    14. }
    To copy to clipboard, switch view to plain text mode 

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

  9. #9
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    Is exactly the same command working in command line ?
    Do it need some sort of interaction ?

  10. #10
    Join Date
    Dec 2015
    Posts
    35
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    Is exactly the same command working in command line ?
    Yes the same :
    Qt Code:
    1. git clone ssh://user@host:port/Template.git
    To copy to clipboard, switch view to plain text mode 

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

    Cmd line screenshot: Capture du 2016-05-19 14:15:53.png

  11. #11
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    I have no idea

  12. #12
    Join Date
    Dec 2015
    Posts
    35
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    Hii,

    There is no error in the programm
    Qt Code:
    1. projectClone = "git clone ssh://user@host:port/Template.git";
    2. process.start(projectClone);
    3.  
    4. if (!process.waitForStarted()) {
    5. qDebug() << "Error : " << process.errorString();
    6. return 1;
    7. }
    8.  
    9. if(!process.waitForFinished())
    10. {
    11. qDebug() << "Error Waiting : " << process.errorString();
    12. return 1;
    13. }
    To copy to clipboard, switch view to plain text mode 

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

  13. #13
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    Before process.start() put in code :
    Qt Code:
    1. qDebug() << QDir::current();
    To copy to clipboard, switch view to plain text mode 

  14. #14
    Join Date
    Dec 2015
    Posts
    35
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Git

    Thanks it works

Similar Threads

  1. QProcess crashes second QProcess
    By Ion in forum Newbie
    Replies: 1
    Last Post: 23rd September 2014, 21:00
  2. Replies: 1
    Last Post: 3rd June 2013, 13:11
  3. Replies: 0
    Last Post: 23rd March 2013, 19:23
  4. Replies: 0
    Last Post: 26th August 2010, 10:44
  5. QProcess inside QProcess
    By bunjee in forum Qt Programming
    Replies: 7
    Last Post: 4th December 2008, 00:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.