[Qt-creator] Update QtCreator kits thru plugin
Antonio Di Monaco
tony at becrux.com
Mon Jan 1 21:19:10 CET 2018
Hi Arun,
my kits are created when the project is loaded. My code starts in Project::fromMap method.
In case you'd like to create your kits at plugin startup, then you need a different method, i.e. YourPluginClass::extensionsInitialized or YourPluginClass::initialize (I assume the first one is better).
Of course, you cannot create any target, just kits, toolchains and tools.
Thanks,
A.
From: "Vidhya Arun" svidhyapria at gmail.com
To: "Antonio Di Monaco" tony at becrux.com
Cc: qt-creator at qt-project.org
Date: Mon, 1 Jan 2018 22:51:15 +0530
Subject: Re: [Qt-creator] Update QtCreator kits thru plugin
Hi Antonio
Tried your steps and built the plugin. Is the kit expected to be listed automatically under Tools/Options/Build &Run/Kits once the plugin is built and loaded successfully in Qt creator ?
Unfortunately I dont see my kit listed there when i execute the plugin ?
Meanwhile are all the steps mandatory to be followed. Initially I just wanted to check if the kit gets created with the registered kit name and toolchain, sysroot details added in plugin.
Thats not happening yet. Any hints on what could have gone wrong here ?
-Vidhya
On Thu, Dec 28, 2017 at 10:21 PM, Antonio Di Monaco <tony at becrux.com> wrote:
Hi Arun,
unfortunately I cannot share the code, but I can provide you some basic steps in order to do that. Please note that what I'm posting is just the result of my understanding of the Qt Creator code, so I could be not correct 100%. I was not able to find any kind of documentation, so YMMV.
Basically, you need to create a toolchain first. You can subclass from ProjectExplorer::GccToolchain, in order to create a GCC/Clang toolchain, or ProjectExplorer::Internal::AbstractMsvcToolchain, for MSVC compiler (yeah, that should not be allowed, but there are no MSVC base classes that are exported through the PROJECTEXPLORER_EXPORT macro. Anyway, it works, you just need some code from MsvcToolchain class).
Once you have it, create a Kit in your Project class. You can do it in the fromMap method, for example (called when your project is loaded):
ProjectExplorer::Kit *kit = new ProjectExplorer::Kit(YOUR_ID);
kit->setUnexpandedDisplayName(YOUR_DISPLAY_NAME);
kit->setAutoDetected(false);
You can add your personal values too, using:
kit->setValueSilently(KEY, VALUE);
that you can access later calling kit->value(KEY).
Then, you can add all the required information:
- sysroot:
ProjectExplorer::SysRootKitInformation::setSysRoot(kit, PATH_OF_THE_SYSROOT);
- toolchain:
ProjectExplorer::ToolChain *tc = new Your_ToolChain_Class(...);
ProjectExplorer::ToolChainManager::registerToolChain(tc);
ProjectExplorer::ToolChainKitInformation::setToolChain(kit, tc);
you can add one for C, and one for C++, according to the LanguageId that you specify in Your_ToolChain_Class.
- If you have a CMake configuration for your kit, you can add it too:
/* vvvvv do this group once vvvvv */
CMakeProjectManager::CMakeTool *cmakeTool = new CMakeProjectManager::CMakeTool(CMakeProjectManager::CMakeTool::ManualDetection, THE_ID_OF_YOUR_CMAKE_COMMAND);
cmakeTool->setAutorun(false);
cmakeTool->setCMakeExecutable("....");
cmakeTool->setDisplayName("....");
CMakeProjectManager::CMakeToolManager::registerCMakeTool(cmakeTool);
/* ^^^^^ do this group once ^^^^^^ */
CMakeProjectManager::CMakeKitInformation::setCMakeTool(kit, THE_ID_OF_YOUR_CMAKE_COMMAND);
CMakeProjectManager::CMakeGeneratorKitInformation::setGenerator(kit, "...");
CMakeProjectManager::CMakeGeneratorKitInformation::setExtraGenerator(kit, "....");
CMakeProjectManager::CMakeConfigurationKitInformation::setConfiguration(kit, CMakeProjectManager::CMakeConfig(...));
- Qt can be set up in a similar way. Unfortunately, I don't know how, cause I'm not using Qt libraries for my kit, so I clear out the information in the kit:
QmakeProjectManager::QmakeKitInformation::setMkspec(kit, Utils::FileName());
QtSupport::QtKitInformation::setQtVersionId(kit, 0);
Maybe you can have a look at those function calls, and specify different parameters.
- Debugger:
Debugger::DebuggerItem debugger;
debugger.setCommand("...");
debugger.setEngineType(Debugger::GdbEngineType or Debugger::CdbEngineType);
debugger.setUnexpandedDisplayName("...");
debugger.setAutoDetected(true);
debugger.setAbi(tc->targetAbi());
debugger.setWorkingDirectory("...");
debugger.reinitializeFromFile();
Debugger::DebuggerKitInformation::setDebugger(kit, Debugger::DebuggerItemManager::registerDebugger(debugger));
- Device type (Desktop in my case):
ProjectExplorer::DeviceTypeKitInformation::setDeviceTypeId(kit, ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
When you're done, you register the kit:
ProjectExplorer::KitManager::registerKit(kit);
In order to consume it, you need a target:
ProjectExplorer::Target *tgt = createTarget(kit);
tgt->setDefaultDisplayName("...");tgt->setDisplayName("...");addTarget(tgt);
That's it.
Toolchains can be unregistered using:
ProjectExplorer::ToolChainKitInformation::clearToolChain(kit, tc->language());ProjectExplorer::ToolChainManager::deregisterToolChain(tc);
So the debugger:
const Debugger::DebuggerItem *dbgItem = Debugger::DebuggerKitInformation::debugger(kit);
if (dbgItem)
Debugger::DebuggerItemManager::deregisterDebugger(dbgItem->id());
the kit:
ProjectExplorer::KitManager::deregisterKit(kit);
and your CMake tool:
CMakeProjectManager::CMakeToolManager::deregisterCMakeTool(THE_ID_OF_YOUR_CMAKE_COMMAND);
Those are the basics. If you need more help, please ask for a specific topic, cause it's very wide to be fully explained.
Hope that this will help you.
BR,
Antonio
From: "Vidhya Arun" svidhyapria at gmail.com
To: "Antonio Di Monaco" tony at becrux.com
Cc: qt-creator at qt-project.org
Date: Wed, 27 Dec 2017 16:45:01 +0000
Subject: [Qt-creator] Update QtCreator kits thru plugin
Hi
I am trying to create my plugin to create the kit to update sysroot, target connection details,etc.
But I couldn't locate how to update sysroot and other details of Qt creator thru plugin. Any suggestions would be appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20180101/0085f2a0/attachment.html>
More information about the Qt-creator
mailing list