c++ - Using CMake with Qt5 and Qt Plugins (Ubuntu 12.04) -
i'd avoid using qmake , .pro files. problem cannot cmake work nicely qt plugins. i've included code below showing interface, plugin, loader work correctly given .pro file cannot figure out how transfer functionality cmake.
plugin interface
pure virtual interface, known loader.
#include <qtcore/qglobal.h> class helloplugininterface { public: virtual void dosomething() const = 0; }; q_declare_interface( helloplugininterface, "com.harbrick.qt.helloplugininterface") plugin
plugin becomes .so loaded loader.
#include <qtplugin> #include "helloplugin_global.h" class helloplugin : public qobject, public helloplugininterface { q_object q_plugin_metadata( iid "com.harbrick.qt.helloplugininterface" ) q_interfaces( helloplugininterface ) public: void dosomething() const; }; plugin loader
void mainwindow::loadplugin( const qstring& pathtolibrary ) { qpluginloader loader( pathtolibrary ); qobject* instance = loader.instance(); if( instance ) { helloplugininterface *plugin = qobject_cast< helloplugininterface* >( instance ); if(plugin) { //do stuff ... } else { qdebug() << "not plugin: " << filename << " = " << loader.errorstring(); } } } cmakelists.txt
can't work
project( helloplugin ) cmake_minimum_required( version 2.8.11 ) set( cmake_include_current_dir on ) find_package(qt5widgets) include_directories( ${cmake_current_source_dir} ) set( include cmakeplugin.h cmakeplugininterface.h ) set( sources cmakeplugin.cpp ) add_executable(${project_name} ${include} ${sources} ${src_list}) add_library( cmakeplugin shared cmakeplugin.cpp ) qmake .pro
works
qt += widgets target = helloplugin template = lib sources += helloplugin.cpp headers += helloplugin.h \ helloplugin_global.h config += plugin debug installs += target
Comments
Post a Comment