Расширение для QtCreator



  • Есть такая статья http://habrahabr.ru/post/135289/

    Возникают вопросы по написанию плагина к QtCreator, как в коде плагина получить следующее:

    Путь к папке Qt- библиотек.

    Путь к исполняемому файлу (exe) текущей сборки текущего открытого активного проекта ?

    Нашел в следующие http://doc.qt.digia.com/qtcreator-extending/projectexplorer.htm, но
    функции :
    @QString binPath () const@

    не видит в пространстве ProjectExplorer, смотрел в исходники там её тоже не нашел.

    Win7, x32, Qt5.0.2, QtCreator 2.7.0


  • Moderators

    I have been using google translate to read this, so my reply might be off the mark:-)

    1. Finding the currently used Qt version: The current project should be available as ProjectExplorerPlugin::startupProject(). That has an active target (activeTarget()), which has a kit (kit()). The kit in turn may contain a Qt version (BaseQtVersion). Get it with QtSupport::QtKitInformation::qtVersion(kit). That Qt version has information on the information Creator has on the Qt version.

    2. Finding the exectuables that are going to be run is a bit more tricky, as that depends a lot on where you want to run the binaries. In principle the RunConfiguration defines what is to be run. You can get those from the activeTarget()->activeRunConfiguration().

    Hope this helps.



  • For example, I want to get

    C:\Users\fujitsu\Documents\QtCreator\TestQt5\release\myprog.exe

    C:\Qt\Qt5.0.2\MSVC\5.0.2\msvc2010_opengl\bin

    I try

    @void MyPluginPlugin::triggerAction()
    {
    ExtensionSystem::PluginManager pm = ExtensionSystem::PluginManager::instance();
    QObject
    obj= pm->getObjectByClassName(tr("ProjectExplorer::ProjectExplorerPlugin"));
    ProjectExplorer::ProjectExplorerPlugin* pep= dynamic_castProjectExplorer::ProjectExplorerPlugin*(obj);
    ProjectExplorer::Project* p= pep->startupProject();

    QListWidget* listWidget = new QListWidget;

    if(pep != nullptr)
    listWidget->addItem(tr("Ok!"));
    else
    listWidget->addItem(tr("Bad!"));

    listWidget->show();
    }
    @

    But :

    bq. Link unresolved external symbol
    "__declspec(dllimport) public: class ProjectExplorer::Project * __thiscall ProjectExplorer::ProjectExplorerPlugin::startupProject(void) const " (_imp?startupProject@ProjectExplorerPlugin@ProjectExplorer @@QBEPAVProject@2@XZ) в функции "private: void __thiscall MyPlugin::Internal::MyPluginPlugin::triggerAction(void)" (?triggerAction@MyPluginPlugin@Internal@MyPlugin@@AAEXXZ)


  • Moderators

    You can replace lines 3-5 with

    @ProjectExplorer::ProjectExplorerPlugin *pep = ProjectExplorerPlugin::instance();@

    I can not understand the error message, so I can not help with that, sorry. Can you get english output somehow?



  • Ru: Я уже нашёл в чем причина ошибки. Нужно было выполнить qmake
    На данный момен мне не удается получить полный путь к исполняемому файлу.

    En: I have found the reason for the error. It was necessary to perform qmaku
    At this moment I can not get the full path to the executable file



  • Еarlier for QtCreator2.7.0 I am use code in my plagin

    @void DLLCollectorPlugin::triggerAction()
    {
    ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();

     QObject* obj= pm->getObjectByClassName(tr("ProjectExplorer::ProjectExplorerPlugin"));
    
     if(! obj)
        {
          QMessageBox::critical(0,tr("Error"),tr("Object \"ProjectExplorerPlugin\" not found!"));
          return;
        }
    
    
     ProjectExplorer::ProjectExplorerPlugin* pep=
             dynamic_cast<ProjectExplorer::ProjectExplorerPlugin*>(obj);
    
     if(! pep)
        {
          QMessageBox::critical(0,tr("Error"),tr("Can not cast Object to ProjectExplorerPlugin"));
          return;
        }
    
     ProjectExplorer::Project* project= pep->currentProject();
    
     if(! project)
        {
          QMessageBox::critical(0,tr("Error"),tr("Current project not found!"));
          return;
        }
    
    
     ProjectExplorer::Target* target= project->activeTarget();
    
     if(! target)
        {
          QMessageBox::critical(0,tr("Error"),tr("Active target not found!"));
          return;
        }
    
     ProjectExplorer::LocalApplicationRunConfiguration* larc=
             dynamic_cast<ProjectExplorer::LocalApplicationRunConfiguration*>(target->activeRunConfiguration());
    
     if(! larc)
        {
          QMessageBox::critical(0,tr("Error"),tr("Can not cast RunConfiguration to LocalApplicationRunConfiguration"));
          return;
        }
    
    
     QString exeFileName= larc->executable();
     Utils::Environment enviroment= larc->environment();@
    

    To take current "enviroment" but now for QtCreator 3.0 а have problem :

    @Utils::Environment enviroment= larc->environment();@
    <<Error: C2512: Utils :: Environment :: Environment: no suitable default constructor>>

    Because "enviroment()" method not member in "ProjectExplorer::LocalApplicationRunConfiguration"

    How can I get "environment" now?


Log in to reply
 

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