Qt5迁移Qt6后插件加载失败:未定义符号_ZN7GscreenD1Ev
Qt5迁移至Qt6后插件因未定义符号
_ZN7GscreenD1Ev无法加载 我们已将应用从Qt5迁移至Qt6,主应用代码经调整后可正常运行,但所有Qt插件均因未定义符号_ZN7GscreenD1Ev无法加载,希望能得到排查帮助。
我们使用CMake编译主应用与插件,相关代码如下:
插件的CMake配置
cmake_minimum_required(VERSION 3.24) project(helloworld) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/") find_package(Qt6 REQUIRED COMPONENTS Core Gui) qt_standard_project_setup() include_directories(${Qt6Core_INCLUDE_DIRS} ${Qt6Gui_INCLUDE_DIRS} ${LIBUSB_1_INCLUDE_DIRS}) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -ggdb") set(helloworld_SRC helloworld.cpp ../../gscreen.hpp ../../plugininterface.hpp ) qt6_add_plugin(helloworld SHARED ${helloworld_SRC} ${helloworld_QRC}) qt_add_resources(helloworld_QRC helloworld.qrc) #add_library(helloworld SHARED ${helloworld_SRC} ${helloworld_QRC}) target_link_libraries(helloworld ${Qt6Core_LIBRARIES} ${Qt6Gui_LIBRARIES}) message("Plugins dir ${PLUGINS_DIR}") install(TARGETS helloworld LIBRARY DESTINATION ${PLUGINS_DIR})
主应用目录中的插件接口代码
#ifndef plugininterface_H #define plugininterface_H #include <QImage> #include <QObject> #include <QString> #include <QtPlugin> enum gAction { displayFullScreen, displayScreen, setKeyBackground, setLcdBrightness, grabFocus, releaseFocus, restoreKeyBackground }; class PluginInterface { public: virtual ~PluginInterface() {} virtual void lKeys(int keys) = 0; virtual QString getName() = 0; virtual QImage getIcon() = 0; virtual void setActive(bool active) = 0; virtual bool isPopup() = 0; virtual QObject *getQObject() = 0; virtual void mKeys(int keys) = 0; private: }; Q_DECLARE_INTERFACE(PluginInterface, "PluginInterface"); #endif
插件头文件代码
#ifndef HELLOWORLD_H #define HELLOWORLD_H #include "../../gscreen.hpp" #include "../../plugininterface.hpp" #include <QtCore> #include <QtPlugin> class HelloWorld : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) Q_PLUGIN_METADATA(IID "your-string-here") public: HelloWorld(); ~HelloWorld() override; void lKeys(int keys) override; QString getName() override; QImage getIcon() override; void setActive(bool active) override; bool isPopup() override; QObject *getQObject() override; void mKeys(int keys) override; private: Gscreen *screen; bool isActive; void paint(); signals: void doAction(gAction action, void *data); // Signal to draw img on screen }; #endif // HELLOWORLD_H
内容的提问来源于stack exchange,提问作者JimmyD
相关产品推荐
相关产品推荐

