[SOLVED] I can not create plugin.



  • I sampled from "echoplugin":http://qt-project.org/doc/qt-4.8/tools-echoplugin.html example to make own plugin.
    My plugin Interface
    @
    #ifndef MODULEINTERFACE_H
    #define MODULEINTERFACE_H
    #include <QString>

    class ModuleInterface
    {
    public:

    virtual ~ModuleInterface() {}
    virtual QString display(QString *);
    virtual QString execute(QString *);
    };

    QT_BEGIN_NAMESPACE

    #define ModuleInterface_iid "proje.tc.ModuleInterface"

    Q_DECLARE_INTERFACE(ModuleInterface,ModuleInterface_iid)

    QT_END_NAMESPACE

    #endif // MODULEINTERFACE_H

    @

    But always I got these errors.
    @
    /home/ckurdu/Documents/my_works/C++/qt/my_projects/qtcms-modules/menu/menu/moduleinterface.h:16: error: expected identifier before string constant
    #define ModuleInterface_iid "proje.tc.ModuleInterface"

    /home/ckurdu/Documents/my_works/C++/qt/my_projects/qtcms-modules/menu/menu/moduleinterface.h:16: error: expected ',' or '...' before string constant
    #define ModuleInterface_iid "proje.tc.ModuleInterface"

    /home/ckurdu/bin/Qt_5_4/5.4/gcc_64/include/QtCore/qobjectdefs_impl.h:49: error: expected constructor, destructor, or type conversion before 'namespace'
    namespace QtPrivate {
    ^
    ^ ^

    @

    My pro file

    @
    TEMPLATE = lib
    CONFIG += plugin
    QT += sql script
    QT -= gui
    SOURCES += menu.cpp
    HEADERS += menu.h
    moduleinterface.h
    TARGET = $$qtLibraryTarget(qtcmsmenu)
    #DESTDIR = ../plugins
    #! [0]

    EXAMPLE_FILES = menuplugin.json

    DESTDIR = /home/ckurdu/Documents/my_works/C++/qt/qtbin/qtcms_modules/menu/

    @

    And I can't see any generated moc files.

    What is the problem?


  • Lifetime Qt Champion

    Hi,

    You need to either make display and execute pure virtual or give them an implementation.

    On a side note, why are you passing pointers to QString ? Most of the time it's not needed. QString is one of the implicitly shared class of Qt.



  • Actually I have given them an implementation that I didn't write here. I solved the problem with changing the order of header files in real plugin file.
    Firstly I included QObject and QtPlugin and after interface header file and problem disappear.

    I will change the pointers. Thank you SGaist.

    @
    #ifndef MODULEPLUGIN_H
    #define MODULEPLUGIN_H
    #include <QObject>
    #include <QtPlugin>
    #include "moduleinterface.h" // I changed location for this line.

    class ModulePlugin : public QObject, ModuleInterface
    {
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "proje.tc.ModuleInterface")
    Q_INTERFACES(ModuleInterface)
    public:
    QString display(QString *command) Q_DECL_OVERRIDE;
    QString execute(QString *command) Q_DECL_OVERRIDE;
    };

    #endif // MODULEPLUGIN_H
    @


Log in to reply
 

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