Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trouble building a plugin in Qt5 wtih CMake for my project.
Forum Updated to NodeBB v4.3 + New Features

Trouble building a plugin in Qt5 wtih CMake for my project.

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 887 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dtmoodie
    wrote on last edited by
    #1

    I'm trying to make a program that will be extensible via plugins. I've modeled it somewhat off of cloud compare: https://github.com/cloudcompare/trunk but I can't get my plugin's to load correctly.

    My interface:

    @class NodePluginFactory
    {

    public:
    NodePluginFactory() {}
    virtual ~NodePluginFactory() {}
    virtual QStringList nodes() const = 0;
    virtual boost::shared_ptrEagleLib::Node createNode(const QString& nodeName, QWidget* parent) = 0;

    };
    Q_DECLARE_INTERFACE(NodePluginFactory, "com.danalex.EagleLib.NodePluginFactory/0.1")
    @

    My Plugin:

    @#include <QObject>
    #include "../../EagleLib/include/Factory.h"
    #include "../../EagleLib/include/nodes/Node.h"
    #include <list>

    class VisualizationFactory: public QObject, public NodePluginFactory
    {
    Q_OBJECT
    Q_INTERFACES(NodePluginFactory)
    Q_PLUGIN_METADATA(IID "myTestPlugin")
    public:
    VisualizationFactory(QObject* parent = 0);
    virtual ~VisualizationFactory() {}
    virtual QStringList nodes();
    virtual EagleLib::Node::Ptr createNode(const std::string &nodeName, QWidget* parent);
    private:
    std::map<std::string, EagleLib::NodeFactory::Ptr> factories;
    };

    @

    My Plugin cmake file:

    @cmake_minimum_required(VERSION 2.8)
    PROJECT(VisualizationPlugin)

    find_package(Qt5 REQUIRED Core)
    INCLUDE_DIRECTORIES(
    ${Qt5Core_INCLUDE_DIRS}
    ${QT_QTCORE_INCLUDE_DIR}
    ${QT_INCLUDE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}

    )

    SET(src Visualization.cpp)
    SET(hdr Visualization.hpp)
    message(${CMAKE_CURRENT_SOURCE_DIR})
    QT5_WRAP_CPP(MOC ${hdr} ${src})
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")

    add_library(VisualizationPlugin SHARED ${src} ${hdr} ${MOC})

    TARGET_LINK_LIBRARIES(VisualizationPlugin
    Qt5::Core

    )
    qt5_use_modules(${PROJECT_NAME} Core)
    @

    Everything builds correctly, but when I try to load the plugin, I always get a null return from loader.instance():

    @void MainWindow::on_pushButton_clicked()
    {
    QDir dir(qApp->applicationDirPath());
    dir.cd("plugins");
    QStringList filters;
    filters << ".so";
    foreach(QString fileName, dir.entryList(filters))
    {
    QPluginLoader loader(dir.absoluteFilePath(fileName));
    QObject
    plugin = loader.instance();
    if(plugin)
    {
    NodePluginFactory* NodePlugin = qobject_cast<NodePluginFactory*>(plugin);
    }
    }
    }
    @

    CloudCompare is pretty much the best example that I've been able to find that works, is with CMake and uses Qt5. And I've checked and double checked but I can't seem to find what I'm missing. I could really use some pointers here.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved