First, environmental preparation
Before writing qt Creator plug-in yourself, you need to compile the source code of Qt Creator. See the blog for details:
Use Qt Creator IDE+MSVC2015 compiler combination to compile Qt Creator source version 4.8.2
Second, the compiler uses MSVC2015 32bit, Qt Creator source compiled, will generate a lot of exe, lib and DLL. We need to focus on the following lib. Because the Qt Creator plugin relies on them.
Debug\lib\qtcreator\Aggregationd4.lib
Debug\lib\qtcreator\Cored4.lib
Debug\lib\qtcreator\ExtensionSystemd4.lib
Debug\lib\qtcreator\Utilsd4.lib
Release\lib\qtcreator\Aggregation4.lib
Release\lib\qtcreator\Core4.lib
Release\lib\qtcreator\ExtensionSystem4.lib
Release\lib\qtcreator\Utils4.lib
3. Create qt Creator plug-in project
Reference Qt – snapshots of the official document doc. Qt. IO/qtcreator – e…
Pro file Settings are as follows:
DEFINES += FIRECAT_TOOLBAR_LIBRARY # firecat_Toolbar files SOURCES += \ firecat_toolbarplugin.cpp HEADERS += \ firecat_toolbarplugin.h \ firecat_toolbar_global.h \ firecat_toolbarconstants.h # Qt Creator linking ## Either set the IDE_SOURCE_TREE when running qmake, ## or set the QTC_SOURCE environment variable, to override the default setting #isEmpty(IDE_SOURCE_TREE): IDE_SOURCE_TREE = $$(QTC_SOURCE)# comment out the sentence isEmpty(IDE_SOURCE_TREE) IDE_SOURCE_TREE = "D:/temp/qt-creator-opensource-src-4.8.2 running qmake, ## or set the QTC_BUILD environment variable, to override the default setting #isEmpty(IDE_BUILD_TREE): IDE_BUILD_TREE = $$(QTC_BUILD)# comment out this sentence #isEmpty(IDE_BUILD_TREE): IDE_BUILD_TREE = "D:/temp/build_plugins"# IDE_BUILD_TREE = "D:/temp/build_plugins/debug/" Build_tree = "D:/temp/build_plugins/release/"# uncomment to build plugin into user config directory ## <localappdata>/plugins/<ideversion> ## where <localappdata> is e.g. ## "%LOCALAPPDATA%\QtProject\qtcreator" on Windows Vista and later ## "$XDG_DATA_HOME/data/QtProject/qtcreator" or "~/.local/share/data/QtProject/qtcreator" on Linux ## "~/Library/Application Support/QtProject/Qt Creator" on OS X #USE_USER_DESTDIR = yes # this sentence must be commented out, otherwise the plugin will be generated in the default path: C:\Users\firecat\AppData\Local\QtProject\QtCreator\plugins\4.8.2 ###### If the plugin can be depended upon by other plugins, this code needs to be outsourced to ###### <dirname>_dependencies.pri, where <dirname> is the name of the directory containing the ###### plugin's sources. QTC_PLUGIN_NAME = firecat_Toolbar QTC_LIB_DEPENDS += \ # nothing here at this time QTC_PLUGIN_DEPENDS += \ coreplugin QTC_PLUGIN_RECOMMENDS += \ # optional plugin dependencies. nothing here at this time ###### End _dependencies.pri contents ###### include($$IDE_SOURCE_TREE/src/qtcreatorplugin.pri) RESOURCES += \ res.qrcCopy the code
Note: The path pointing must be correct, otherwise the compilation will fail
IDE_SOURCE_TREE refers to the source path for Qt Creator
2, IDE_BUILD_TREE refers to the path generated by the plug-in. It must be clear otherwise it will run to the default path:
C:\Users\< user name >\AppData\Local\QtProject\QtCreator\plugins\4.8.2
3, the include ($$IDE_SOURCE_TREE/SRC/qtcreatorplugin pri)
4. Select Release for plug-in compilation, because debug is meaningless and useless.
4. Write plug-in code. My purpose is to add my frequently used functions to the left toolbar:
The first new button is calculator, which calls Microsoft Calculator when clicked;
The second new button is run without deployment;
The third new button is to ignore deployment and start debugging directly.
bool firecat_ToolbarPlugin::initialize(const QStringList &arguments, QString *errorString) { // Register objects in the plugin manager's object pool // Load settings // Add actions to menus // Connect to other plugins' signals // In the initialize function, a plugin can be sure that the plugins it // depends on have initialized their members. Q_UNUSED(arguments) Q_UNUSED (errorString) / / we affirmative RunWithoutDeploy this method to the toolbar, easy to use const char id1 [] = "ProjectExplorer. RunWithoutDeploy"; / / this id is corresponding to the Qt Creator source const char RUNWITHOUTDEPLOY [] QAction * act1 = Core: : ActionManager: : command (id1) - > action (); M_runWithoutDeployAction if (act1 == NULL) {return false; } const Utils::Icon CLASSIC1(":/image/mode_run.png"); / / 32 bit image, 34 * pixel const Utils: : Icon FLAT1 ({{" : / image/mode_run_mask PNG ", Utils: : Theme: : IconsRunToolBarColor}}); Const Utils::Icon FLAT_ACTIVE1({{":/image/mode_run_mask. PNG ", Utils::Theme::IconsModeWelcomeActiveColor}}); act1->setIcon(Utils::Icon::modeIcon(CLASSIC1, FLAT1, FLAT_ACTIVE1)); //act1->setIcon(Utils::Icon::sideBarIcon(CLASSIC1, FLAT1)); act1->setVisible(true); Core::ModeManager::addAction(act1, 130); / / we affirmative DebugWithoutDeploy this method to the toolbar, easy to use const char id2 [] = "the Debugger. DebugWithoutDeploy"; QAction *act2 = Core::ActionManager::command(id2)->action(); M_debugWithoutDeployAction if (act2 == NULL) {return false; } const Utils::Icon CLASSIC2(":/image/mode_debug.png"); const Utils::Icon FLAT2({{":/image/mode_debug_mask.png", Utils::Theme::IconsRunToolBarColor}}); const Utils::Icon FLAT_ACTIVE2({{":/image/mode_debug_mask.png", Utils::Theme::IconsModeWelcomeActiveColor}}); act2->setIcon(Utils::Icon::modeIcon(CLASSIC2, FLAT2, FLAT_ACTIVE2)); //act2->setIcon(Utils::Icon::sideBarIcon(CLASSIC2, FLAT2)); act2->setVisible(true); Core::ModeManager::addAction(act2, 120); #if defined(Q_OS_WIN32) QAction *act3 = new QAction(tr("calc"), this); const Utils::Icon CLASSIC3(":/image/mode_calc.png"); const Utils::Icon FLAT3({{":/image/mode_calc_mask.png", Utils::Theme::IconsRunToolBarColor}}); const Utils::Icon FLAT_ACTIVE3({{":/image/mode_calc_mask.png", Utils::Theme::IconsModeWelcomeActiveColor}}); act3->setIcon(Utils::Icon::modeIcon(CLASSIC3, FLAT3, FLAT_ACTIVE3)); //act3->setIcon(Utils::Icon::sideBarIcon(CLASSIC3, FLAT3)); act3->setVisible(true); //QStandardPaths::standardLocations(QStandardPaths::DesktopLocation); Wchar_t szPath[MAX_PATH] ={0}; GetSystemDirectory(szPath, MAX_PATH); QString path = QString::fromWCharArray(szPath); connect(act3, &QAction::triggered, this, [=]() { QProcess *poc = new QProcess; poc->start(path + "\\calc.exe"); / / that is "C: \ \ Windows \ \ system32 \ \ calc exe"}); Core::ModeManager::addAction(act3, 150); #endif // because Qt Creator source code has defined the position of the priority // Action priorities //const int P_ACTION_RUN = 100; //const int P_ACTION_BUILDPROJECT = 80; //const int P_ACTION_DEBUG = 90; // Priority for the modemanager. //ModeManager::addAction(cmd->action(), Constants::P_ACTION_RUN); return true; }Copy the code
Release builds firecat_toolbar4.dll and places it in the official Qt Creator installation path.
D: \ Qt \ Qt5.9.8 \ Tools \ QtCreator \ lib \ QtCreator \ plugins \
Note that the Qt Creator IDE for Windows is compiled using MSVC2015 32bit.
Done (#^.^#)
Five, the complete project source code and library file download link:
Download.csdn.net/download/li…
The source folder has the firecat_tools.json. in file. Change it to:
{
\"Name\" : \"firecat_Toolbar\",
\"Version\" : \"$$QTCREATOR_VERSION$$VERSION_SUFFIX\",
\"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\",
\"Vendor\" : \"firecatStudio\",
\"Copyright\" : \"firecatStudio\",
\"License\" : \"\",
\"Description\" : \"\",
\"Url\" : \"\",
$$dependencyList
}
Copy the code
This ADAPTS to the QtCreator version number
If you want to know how Qt Creator works, check out my next blog post:
Qt Creator plugin hands-on practice (3) C++ class ModeManager source analysis
—
Ico Icon Download
icons8.com/
www.easyicon.net/