我写了一些内核来动态加载* .dll文件。作为主要工具,我使用Qt 5.12企业版。该dll必须通过QLibrary下载其他qobject继承的类,以在核心程序中进行连接和使用,以便通过信号/插槽进行连接。但是当编译dll时,应该通过qlibrary下载该文件,我收到一条错误消息“ vtable,驱动程序接口的未定义引用”,我在堆栈溢出时看到了相同的问题,但是其中的解决方案就像尝试清理和重建项目一样,没有。为我工作。也许我应该包括其他Moc文件,但是哪一个呢?我使用qmake作为构建系统。所有纯虚方法都在继承的类中重新定义。在下面列出。
#ifndef DRIVER101104_H
#define DRIVER101104_H
#include "driver101-104_global.h"
#include "driverinterface.h"
#include "protocol101104wrapper.h"
#include <QObject>
#include <functional>
#include <QHash>
class Driver101104 : public DriverInterface
{
Q_OBJECT
public:
Driver101104();
virtual ~Driver101104();
// DriverInterface interface
public:
void setMessageAsString(const QString &_message);
QString getMessageAsString();
void initializeChannel(const QJsonObject& _parameters);
bool downloadTagsModel(const QHash<QString, std::shared_ptr<TagModel> > &_tagModels);
void setCallBackFunction(const QString &_nameOfCallBack, std::function<void (const QString &)> _callback);
private:
protocol101104Wrapper wrapper;
};
extern "C"{
DRIVER101104SHARED_EXPORT DriverInterface* createDriverClass(){
return new Driver101104();
}
}
#endif // DRIVER101104_H
#ifndef DRIVERINTERFACE_H
#define DRIVERINTERFACE_H
#include <QHash>
#include <memory>
#include <functional>
#include <QJsonObject>
#include <QObject>
class TagModel;
class DriverInterface : public QObject
{
Q_OBJECT
public:
DriverInterface() : QObject(nullptr){
}
virtual ~DriverInterface() {
}
/*This methods are for external type of driver connection!
* All other logick have to be In usual cases.*/
virtual void setMessageAsString(const QString& _message) = 0;
virtual QString getMessageAsString() = 0;
/*This method for type of external LinkAgent and external driver!*/
virtual void initializeChannel(const QJsonObject& _parameters) = 0;
virtual void setCallBackFunction(const QString& _nameOfCallBack,
std::function<void (const QString& _message)> _callBack) = 0;
/*Usual type of working, Device download tags model into it's own storage
* and serialize or deserialize it.*/
virtual bool downloadTagsModel(const QHash<QString, std::shared_ptr<TagModel>>& _tagModels) = 0;
};
#endif // DRIVERINTERFACE_H
#-------------------------------------------------
#
# Project created by QtCreator 2019-10-14T15:08:10
#
#-------------------------------------------------
QT -= gui
TARGET = Driver101-104
TEMPLATE = lib
DEFINES += DRIVER101104_LIBRARY
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
include(LibHeaders.pri)
include(LibSources.pri)
CONFIG += c++11
SOURCES += \
callbacknames.cpp \
driver101104.cpp \
protocol101104wrapper.cpp \
servicenames.cpp
HEADERS += \
callbacknames.h \
driver101104.h \
driver101-104_global.h \
driverinterface.h \
enums.h \
protocol101104wrapper.h \
servicenames.h
unix {
target.path = /usr/lib
INSTALLS += target
}
#include "driver101104.h"
Driver101104::Driver101104():DriverInterface()
{
}
Driver101104::~Driver101104()
{
}
void Driver101104::setMessageAsString(const QString &_message)
{
}
QString Driver101104::getMessageAsString()
{
}
/**
* @brief Driver101104::initializeChannel
* @param _parameters
*/
void Driver101104::initializeChannel(const QJsonObject& _parameters)
{
wrapper.channelInitializer(_parameters);
}
/**
* @brief Driver101104::downloadTagsModel
* Here should be something that return code
* of error for this program
* @param _tagModels
* @return
*/
bool Driver101104::downloadTagsModel(const QHash<QString, std::shared_ptr<TagModel> >& _tagModels)
{
return true;
}
void Driver101104::setCallBackFunction(const QString &_nameOfFunction, std::function<void (const QString&)> _callback)
{
wrapper.setCallBackFunction(_nameOfFunction,_callback);
}
答案 0 :(得分:0)
我找到了这个问题的答案,我重写了driverInterface和driver01104的类,在此之后,所有工作都正确无误。库已加载并且可以正常工作。仅与信号和插槽的连接不起作用。
#ifndef DRIVER101104_H
#define DRIVER101104_H
#include <QObject>
#include <functional>
#include <QHash>
#include "driver101-104_global.h"
#include "protocol101104wrapper.h"
#include "driverinterface.h"
class DRIVER101104SHARED_EXPORT Driver101104 : public DriverInterface
{
Q_OBJECT
public:
Driver101104(QObject* parent = nullptr);
virtual ~Driver101104();
public:
void initializeChannel(const QJsonObject &_parameters);
void setCallBackFunction(const QString &_nameOfCallBack,
std::function<void (const QString &)> _callback);
bool downloadTagsModel(const QHash<QString,
std::shared_ptr<TagModel> > &_tagModels);
void setMessageAsString(const QString &_message);
QString getMessageAsString();
private:
protocol101104Wrapper* wrapper;
};
extern "C"{
DRIVER101104SHARED_EXPORT DriverInterface* createDriverClass();
}
#endif // DRIVER101104_H
#ifndef DRIVERINTERFACE_H
#define DRIVERINTERFACE_H
#include <QObject>
#include <functional>
#include <QString>
#include <memory>
#include <QHash>
#include <QJsonObject>
class TagModel;
class DriverInterface : public QObject
{
Q_OBJECT
public:
DriverInterface(QObject* parent = nullptr): QObject(parent){
}
virtual ~DriverInterface(){
}
virtual void setMessageAsString(const QString& _message) = 0;
virtual void initializeChannel(const QJsonObject& _parameters) = 0;
virtual void setCallBackFunction(const QString &_nameOfCallBack,
std::function<void (const QString &)> _callback) = 0;
virtual bool downloadTagsModel(const QHash<QString,
std::shared_ptr<TagModel> >& _tagModels) = 0;
virtual QString getMessageAsString() = 0;
signals:
void callBackMessage(QJsonObject _message);
};
#endif // DRIVERINTERFACE_H