I migrated our application from Qt5 to Qt6. The code of the main application is working fine after some code changes. But all the QT plugins that are in the application cannot be loaded because of undefined symbol: _ZN7GscreenD1Ev. Hope someone sees the error?
We use cmake to compile the plugins and main applicaton. Cmake file of the plugin looks like:
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})
The interface that the plugins need to implement is laying in the main application directory and looks like:
#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
And the plugin header file:
#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