Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8662215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:40:48+00:00 2026-06-12T16:40:48+00:00

I am in the process of building a Qt application. While I have programmed

  • 0

I am in the process of building a Qt application. While I have programmed lots of GUI things before and the framework itself isn’t presenting a problem, I have not ever programmed anything (outside of C# .NET applications) that has the capability to load plugins. The project I am trying to build has plugins as an integral part of it and I thought the Qt framework looked nice for this because it was almost universally cross-platform and seems to have a very nice system for plugins.

My problem is this: I can’t seem to get the QPluginLoader.instance() method to return anything but a null value.

From my readings, this is because it finds no plugin. I think I am probably forgetting to do something, but I can find very little documentation on actually writing plugins (there are examples, but they aren’t incredibly detailed). There are plenty of examples of loading plugins and I think I am doing that right, but I haven’t really found an example of actually making a plugin.

This is what I have done:

Using Qt-Creator I have created two projects: A windowed application to pretend that it is my plugin receiving application and a Shared Library project to pretend to be the plugin

In my windowed application I have a header file as follows:

#ifndef PLUGININTERFACE_H
#define PLUGININTERFACE_H

#include <QtPlugin>

class QStringList;

class PluginInterface
{
public:
    virtual ~PluginInterface() {};

    virtual QStringList messages() const = 0;
};

Q_DECLARE_INTERFACE(PluginInterface,
                    "com.kevincuzner.LearningPlugins.PluginInterface/1.0")

#endif // PLUGININTERFACE_H

In my shared library application I created a class called ATestPlugin (and this is also the TARGET value of the project):

#ifndef ATESTPLUGIN_H
#define ATESTPLUGIN_H

#include "ATestPlugin_global.h"
#include "../LearningPlugins/PluginInterface.h"

#include <QStringList>


class ATESTPLUGINSHARED_EXPORT ATestPlugin : public PluginInterface, public QObject
{

    Q_OBJECT
    Q_INTERFACES(PluginInterface)

public:
    ATestPlugin();

    virtual QStringList messages() const
    {
        //this part is actually defined in the .cpp file, but I don't feel like pasting that here
        QStringList ret;
        ret << "foo" << "bar" << "noms" << "Hello";

        return ret;
    }
};

#endif // ATESTPLUGIN_H

At the end of the ATestPlugin.cpp file I have placed Q_EXPORT_PLUGIN2(ATestPlugin, ATestPlugin)

Then in my main.cpp file in the main method I do the following (&w points to the main window):

QString text = QFileDialog::getOpenFileName(&w, "Get a file");
QPluginLoader loader(text);
QObject* plugin = loader.instance();
if (plugin)
{
    QMessageBox msgBox;
    msgBox.setText(text);
    msgBox.exec();
}

When I run the program and select libATestPlugin.so from the build directory of my library project in the file dialog that pops up, I see no message box which means *plugin is null. Previously I had the messagebox always pop up and show the selected file name, so I know that part is working.

Does anyone have any ideas as to what I need to do to make my plugin visible to QPluginLoader?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:40:49+00:00Added an answer on June 12, 2026 at 4:40 pm

    After further experimentation I managed to get the plugin to load. I feel sheepish saying this, but it was a classic case of RTFM.

    The echo plugin tutorial (which I hadn’t found until after I posted the question) had some modifications that had to be made to the .pro file in the library to make it declare the plugin correctly:

    The line TARGET = ATestPlugin had to be changed to TARGET = $$qtLibraryTarget(ATestPlugin). After making this change, my messagebox in the above program popped up and later when I ran qobject_cast< PluginInterface* >(plugin) and then asked ran PluginInterface->messages() I got the list which was implemented in the separate class.

    Also, I did change the inheritance order to put QObject first and since it works that way I will probably keep it so (although, I don’t know if it made a difference).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a play application which I am in the process of building a
I have a long running process in my MVC application(C#). Its building data for
Hi We are in process of building new application which will have .Net UI
I'm in the process of building a WPF application and ran into an error
I am building an application and currently am in the process of add backgrounds
I'm in the process of building a support page for my pre application. I'm
I'm in a process of selecting an API for building a GWT application. The
During the process of building software applications, you would start testing what you have
In the process of building a third party bundle for the Symfony2 framework I
In an android activity I have a lenghty process in building a report (view).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.