如何设置插件?

时间:2017-11-22 13:03:53

标签: qt plugins qt5

我已经编写了一个qt应用程序,通过RS232与自定义控制器进行通信。我现在需要通过插件将功能扩展到应用程序。我看过在线提供的Echo插件示例以及我在网上其他地方可以找到的其他内容,但我仍然很丢失,而且非常基本的插件没有编译。该插件的项目.pro文件如下:

TEMPLATE        = lib                                       # making a library, not an executible
CONFIG         += plugin                                    #
QT             += widgets network gui
INCLUDEPATH    += ../vibecreator/vibecreator/               # include path to plugin interface
TARGET          = $$qtLibraryTarget(reactionsserverplugin)  # name of the library file in which the plugin will be stored, should be same as name of the plugin
DESTDIR         = ../plugins

# install
target.path = ../plugins
INSTALLS += target

CONFIG += install_ok  # Do not cargo-cult this!

SOURCES += reactionsserverplugin.cpp

HEADERS  += reactionsserverplugin.h \
    reactionsserverinterface.h

FORMS += \
    reactionfileform.ui

DISTFILES += \
    reactionsserver.plugin.json

头文件是

#ifndef REACTIONSSERVER_PLUGIN_H
#define REACTIONSSERVER_PLUGIN_H

#include <QObject>
#include <QWidget>
#include <QtPlugin>

//#include "../vibecreator/vibecreator/reactionsserverinterface.h"
#include "reactionsserverinterface.h"

namespace Ui {
    class ReactionServerFileForm;
}

class ReactionsServerPlugin : public QWidget, ReactionsServerInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA( IID "org.qt-project.Qt.AddHaptics.ReactionsServerInterface" FILE "reactionsserver.plugin.json" )
    Q_INTERFACES(ReactionsServerInterface)

public:
    void createForm() override;

private:
    Ui::ReactionServerFileForm* ui;

};

#endif // REACTIONSSERVER_GLOBAL_H

源文件是:

#include <QtWidgets>

#include "reactionsserverplugin.h"
#include "ui_reactionfileform.h"

void ReactionsServerPlugin::createForm()
{
    ui = new Ui::ReactionServerFileForm;
    ui->setupUi(this);
}

以下是界面类

#ifndef REACTIONSSERVER_INTERFACE_H
#define REACTIONSSERVER_INTERFACE_H

class ReactionsServerInterface
{

public:
    virtual ~ReactionsServerInterface(){}
    virtual void createForm();
};

#define ReactinonsSeverInterface_iid "org.qt-project.Qt.AddHaptics.ReactionsServerInterface"

Q_DECLARE_INTERFACE(ReactionsServerInterface, ReactinonsSeverInterface_iid)

#endif // REACTIONSSERVER_H

我收到以下错误,据我所知,我没有任何代码失败。

Undefined symbols for architecture x86_64:
  "typeinfo for ReactionsServerInterface", referenced from:
      typeinfo for ReactionsServerPlugin in moc_reactionsserverplugin.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [../plugins/libreactionsserverplugin_debug.dylib] Error 1
13:07:00: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project reactionsserverplugin (kit: Desktop Qt 5.5.1 clang 64bit)
When executing step "Make"

我已在网上搜索此错误的解决方案,但未找到任何结果。

1 个答案:

答案 0 :(得分:0)

typeinfo错误似乎通常与虚函数的声明有关。问题确实存在于界面课上。接口类中createForm函数的声明应如下所示

virtual void createForm() = 0;