You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 16:53:10