2

I'm trying to create my own QtCreator Plugin by following this guide.

So I cloned this repo and checked the v2.8.1 tagged commit out (c3ed746c).

Then I copied my QtCreator 2.8.1 directory and created a new Qt Creator Plugin project.

Then I create a new file in my project directory called MyPlugin.json.

If I try to compile my plug in I get this error:

e:\qtprojects\build-myplugin-desktop_qt_5_1_1_msvc2012_32bit-debug\debug../../MyPlugin/mypluginplugin.h(6) : fatal error C1083: Cannot open include file: "extensionsystem/iplugin.h": No such file or directory jom: E:\QtProjects\build-MyPlugin-Desktop_Qt_5_1_1_MSVC2012_32bit-Debug\Makefile.Debug [debug\moc_mypluginplugin.obj] Error 2 jom: E:\QtProjects\build-MyPlugin-Desktop_Qt_5_1_1_MSVC2012_32bit-Debug\Makefile [debug] Error 2 10:56:51: The process "E:\Qt\Qt5\Tools\QtCreator\bin\jom.exe" exited with code 2. Error while building/deploying project myplugin (kit: Desktop Qt 5.1.1 MSVC2012 32bit) When executing step 'Make' 10:56:51: Elapsed time: 00:01.

What do I have to do to make it work?

This are the source files:

myplugin.pro

DEFINES += MYPLUGIN_LIBRARY

 # MyPlugin files

SOURCES += mypluginplugin.cpp

HEADERS += mypluginplugin.h \
        myplugin_global.h \
        mypluginconstants.h

 # Qt Creator linking

 ## set the QTC_SOURCE environment variable to override the setting here
QTCREATOR_SOURCES = $$(QTC_SOURCE)
isEmpty(QTCREATOR_SOURCES):QTCREATOR_SOURCES=E:/QtProjects/_QtCreatorPlugIns/qt-creator

 ## set the QTC_BUILD environment variable to override the setting here
IDE_BUILD_TREE = $$(QTC_BUILD)
isEmpty(IDE_BUILD_TREE):IDE_BUILD_TREE=E:/QtProjects/_QtCreatorPlugIns/QtCreator

 ## 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 Mac
 # USE_USER_DESTDIR = yes

PROVIDER = MyCompany

include($$QTCREATOR_SOURCES/src/qtcreatorplugin.pri)

myplugin_global.h

#ifndef MYPLUGIN_GLOBAL_H
#define MYPLUGIN_GLOBAL_H

#include <QtGlobal>

#if defined(MYPLUGIN_LIBRARY)
#  define MYPLUGINSHARED_EXPORT Q_DECL_EXPORT
#else
#  define MYPLUGINSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // MYPLUGIN_GLOBAL_H

mypluginconstants.h

#ifndef MYPLUGINCONSTANTS_H
#define MYPLUGINCONSTANTS_H

namespace MyPlugin {
    namespace Constants {

        const char ACTION_ID[] = "MyPlugin.Action";
        const char MENU_ID[] = "MyPlugin.Menu";

    } // namespace MyPlugin
} // namespace Constants

#endif // MYPLUGINCONSTANTS_H

mypluginplugin.h

#ifndef MYPLUGIN_H
#define MYPLUGIN_H

#include "myplugin_global.h"

#include <extensionsystem/iplugin.h>

namespace MyPlugin {
    namespace Internal {

        class MyPluginPlugin : public ExtensionSystem::IPlugin
        {
                Q_OBJECT
                Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "MyPlugin.json")

            public:
                MyPluginPlugin();
                ~MyPluginPlugin();

                bool initialize(const QStringList &arguments, QString *errorString);
                void extensionsInitialized();
                ShutdownFlag aboutToShutdown();

            private slots:
                void triggerAction();
        };

    } // namespace Internal
} // namespace MyPlugin

#endif // MYPLUGIN_H

mypluginplugin.cpp

#include "mypluginplugin.h"
#include "mypluginconstants.h"

#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/coreconstants.h>

#include <QAction>
#include <QMessageBox>
#include <QMainWindow>
#include <QMenu>

#include <QtPlugin>

using namespace MyPlugin::Internal;

MyPluginPlugin::MyPluginPlugin()
{
    // Create your members
}

MyPluginPlugin::~MyPluginPlugin()
{
    // Unregister objects from the plugin manager's object pool
    // Delete members
}

bool MyPluginPlugin::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 method, a plugin can be sure that the plugins it
    // depends on have initialized their members.

    Q_UNUSED(arguments)
    Q_UNUSED(errorString)

    QAction *action = new QAction(tr("MyPlugin action"), this);
    Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID,
                                                             Core::Context(Core::Constants::C_GLOBAL));
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Meta+A")));
    connect(action, SIGNAL(triggered()), this, SLOT(triggerAction()));

    Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID);
    menu->menu()->setTitle(tr("MyPlugin"));
    menu->addAction(cmd);
    Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);

    return true;
}

void MyPluginPlugin::extensionsInitialized()
{
    // Retrieve objects from the plugin manager's object pool
    // In the extensionsInitialized method, a plugin can be sure that all
    // plugins that depend on it are completely initialized.
}

ExtensionSystem::IPlugin::ShutdownFlag MyPluginPlugin::aboutToShutdown()
{
    // Save settings
    // Disconnect from signals that are not needed during shutdown
    // Hide UI (if you add UI that is not in the main window directly)
    return SynchronousShutdown;
}

void MyPluginPlugin::triggerAction()
{
    QMessageBox::information(Core::ICore::mainWindow(),
                             tr("Action triggered"),
                             tr("This is an action from MyPlugin."));
}

Q_EXPORT_PLUGIN2(MyPlugin, MyPluginPlugin)

Directories

E:\QtProjects\_QtCreatorPlugIns> tree

├───qt-creator
│   ├───bin
│   ├───dist
│   ├───doc
│   ├───lib
│   ├───qbs
│   ├───scripts
│   ├───share
│   ├───srcn64interrupt
│   └───testsster
├───QtCreator
│   ├───bin
│   ├───lib0
│   └───share

1 Answer 1

3

If you're a linux user, you can download qtcreator-dev. But, i don't know how it works on Windows.

  1. Open terminal
  2. Type : sudo apt-get install qtcreator-dev
  3. Done.
Sign up to request clarification or add additional context in comments.

3 Comments

+1 nice and easy... but how to do on other distros? (Debian has no package qtcreator-dev. Do I need to add some apt-repositories?)
If your distro still use apt. Then it's fine. You can manually add PPA of Ubuntu SDK Team (ppa:ubuntu-sdk-team/ppa) by reading the following guide, webupd8.org/2014/10/…. If not, I doubt, I can't provide the answer. Cheers.
The dev version imho is just Qt Creator build in debug mode. So if (like me) someone is compiling Qt Creator from source, he/she should also do a Debug alongside the Release version of the IDE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.