0

私は自分の問題に非常に神経質になり始めています。誰かが理解してくれることを願っています。1 つの実行可能ファイルといくつかのプラグイン (ランタイム ロード ライブラリ) を生成するプロジェクトがあるとします。その実行可能ファイルは、最初に適切なプラグインを探すある種のデーモン/サービスです。したがって、これらのプラグインは抽象的な通信レイヤーを提供する必要があります。私は Qt Doc を見て、.so からのインターフェイスの読み込みを提供する必要がある QPluginLoader クラスを見つけましたが、インターフェイスはシグナル/スロットを持つことができず、純粋な仮想でなければなりません。それで、QObjectベースのオブジェクトを返す何かを考えていました...

!!! 2 つのインターフェースと 2 つの実装しかないので、怖がらないでください :)

私のプロジェクトのレイアウトと内容:

./Daemon/Interfaces/PluginInterface.h

#include <QObject>
#include "PluginInterface.h"
class PluginInterface {
public:
    virtual ~PluginInterface() = 0;
    virtual ProtocolInterface* getInterface() = 0;
    virtual int getPluginId() const = 0;
};

Q_DECLARE_INTERFACE( PluginInterface, "com.porta.protocol.PluginInterface/1.0")

./Daemon/Interfaces/ProtocolInterface.h

#include <QObject>
#include "turnstile.h"
class ProtocolInterface : public QObject {
    Q_OBJECT
public:
    ProtocolInterface( QObject *parent = 0 ) : QObject( parent ) {}
    virtual QWidget* getConfigureGUI() = 0;
    virtual void init() = 0;
    virtual void start() = 0;
signals:
    void someSignal();
};

./Daemon/ProtocolHander.cpp(&h) <- プラグインのロードといくつかのロジック

./Daemon.pro

QT       += core gui
TARGET = porta_daemon
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app

SOURCES += main.cpp \
protocolhandler.cpp

HEADERS += protocolhandler.h \
Interfaces/protocolinterface.h \
Interfaces/protocolloader.h \
    Interfaces/turnstile.h

./Plugins/Dummy/DummyPluginInterface.h

#include "protocolloader.h"
#include <QObject>
class DummyPluginInterface : public QObject, PluginInterface {
    Q_OBJECT
    Q_INTERFACES(PluginInterface)
public:
    ProtocolInterface* getInterface();
    int getPluginId() const;
};

./Plugins/Dummy/DummyPluginInterface.cpp

#include "DummyPluginInterface.h"
#include "DummyProtocolInterface.h"

ProtocolInterface *DummyPluginInterface::getInterface() {
    return new DummyProtocolInterface();
}

int DummyPluginInterface::getPluginId() const {
    return 1;
}

Q_EXPORT_PLUGIN2(dummyplugin, DummyPluginInterface)

./Plugins/Dummy/DummyProtocolInterface.h

#include "protocolinterface.h"
#include <QObject>

class DummyProtocolInterface : public ProtocolInterface {
public:
    void init();
    QWidget* getConfigureGUI();
    void start();
    int getPluginId() { return 1; }
};

./Plugins/Dummy/DummyProtocolInterface.cpp

#include "DummyProtocolInterface.h"

QWidget* DummyProtocolInterface::getConfigureGUI() {
    return 0;
}

void DummyProtocolInterface::start() {
}

void DummyProtocolInterface::init() {
    emit someSignal(); /// !!! this is important for me
}

./Plugins/Dummy/Dummy.pro

TEMPLATE        = lib
CONFIG         += plugin
QT             += network
INCLUDEPATH += ../../Daemon/Interfaces/
HEADERS        += ****
SOURCES        += ****
TARGET          = *****
DESTDIR         = *****

私の問題は、リンク エラーまたは実行時の未解決のシンボル (主に QObject からのもの) を取得している、または信号を接続できないことです... ProtocolHandler は、信号/スロットを接続するものでなければなりません..

このアプローチを正しくする方法を誰か教えてもらえますか? Qtの例はそのような考えをカバーしていません..

ありがとう!

アダム

4

1 に答える 1

2

したがって、ProtocolInterface.hをPlugin.proファイルのHEADERS+=セクションに追加すると問題が解決しました:)

于 2012-02-01T09:55:50.920 に答える