在 dll 中为 qLibrary 编译 qobject 时出错
Error while compiling qobject in dll for qlibrary
我写了一些核心来动态加载*.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);
}
我找到了这个问题的答案,我重写了 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
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 从R调用C++函数并对其进行集成时出错
- 这个函数哪里出错了
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 为重写std::exception的库生成swig接口时出错
- 在 dll 中为 qLibrary 编译 qobject 时出错
- 调用 qExec "no known conversion for argument 1 to QObject"时出错