How to use the git plugin from Qt Creator in a custom plugin?



  • Hi,

    I'm writing a custom Qt Creator plugin according to this guide.
    And now I want to use the git plugin from Qt Creator (specifically, GitClient class) in my plugin. For this purpose I did next steps:

    • I defined GIT_LIBRARY in "qt-creator-src/src/plugins/git/git.pro" file:
    DEFINES += GIT_LIBRARY
    
    • added git_global.h file to the git plugin with next content:
    #pragma once
    
    #include <qglobal.h>
    
    #if defined(GIT_LIBRARY)
    #  define GIT_EXPORT Q_DECL_EXPORT
    #else
    #  define GIT_EXPORT Q_DECL_IMPORT
    #endif
    
    
    • included git_global.h file in "qt-creator-src/src/plugins/git/gitclient.h" and used GIT_EXPORT in the GitClient class definition:
    #pragma once
    
    #include "git_global.h"
    
    // some code here
    
    class GIT_EXPORT GitClient : public VcsBase::VcsBaseClientImpl {
    
    // and some code here
    
    };
    
    • then I updated dependencies of my plugin:
    QTC_PLUGIN_NAME = MyPlugin
    QTC_LIB_DEPENDS += \
        # nothing here at this time
    
    QTC_PLUGIN_DEPENDS += \
        coreplugin \
        projectexplorer \
        vcsbase \
        git
    
    QTC_PLUGIN_RECOMMENDS += \
        # optional plugin dependencies. nothing here at this time
    
    

    And after all I try to create GitClient object:

    #include <git/gitclient.h>
    
    MyPlugin::MyPlugin()
    {
        Git::Internal::GitClient *git = new Git::Internal::GitClient;
    }
    
    

    but I got an error "undefined reference to `Git::Internal::GitClient::GitClient()'"

    I hope I just missed something, or is this mission impossible? :-)



  • What do you want to do in your plugin?

    If you want to extend git support in creator, then I would be happy to take patches to the git plugin itself. No need to export the vitclient class that way:-)

    It you just need to use git, then can you try to extend the version control interfaces in core to support what you need? That way your plugin has a chance to work with all supported version control systems.

    I am very reluctant to export the GitClient class. That has a lot of methods that should not re exported and will need a big cleanup to be ready for wider exposure.



  • @hunger Hi,
    actually, nothing special:-)
    I just play with creating of custom Qt Creator wizard where I could customize git repo with additional commands (adding remote, for example, or maybe something else) during creating a new project. And for this purpose I decided to use git client from Qt Creator because, as for me, it seems more naturally rather than other approaches (I wrote my own git client at first, just for testing, and it was buggy little bit:-))



  • Ah, yes I really missed one step:-)
    I forgotten to rebuild Qt Creator source and move new git plugin library (libGit.so) to the build directory of the Qt Creator instance which I use to test.
    Now everything works;-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.