Important: Please read the Qt Code of Conduct -

[SOLVED]my Inherited QImageIOPlugin doesn't work!

  • I wrote a plugin called TextImage and I want to use it when I save or load any image with "ti" format...

    here is my .pro File :


    Project created by QtCreator 2014-09-09T12:01:08


    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = textimage
    TEMPLATE = lib
    CONFIG += plugin release
    VERSION = 1.0.0

    SOURCES +=

    HEADERS +=

    target.path += $$[QT_INSTALL_PLUGINS]/imageformats
    INSTALLS += target

    FORMS +=


    with target.path += $$[QT_INSTALL_PLUGINS]/imageformats part, I expect that every time I use save or load function for Qimages with "ti" format it works properly! but it doesn't work at all! I checked imageformats folder and there is not a copy of my plugin! what is wrong?

  • Moderators

    Depends on your OS. If you are using say linux or osx for example chances are you would need root access to install a plugin into Qt.

    I would also highly recommend against installing your plugin into your Qt directory. It should go somewhere else and be added to any project that uses it.

    As for why it isn't working, there could be a million reasons. I'd start with the fact that the plugin isn't in the directory you expect and that it probably isn't loaded into your test application properly.

    Start by including it in your test project and then making sure it is loaded properly.

    "Here": is the documentation you need to get your plugin both deployed and working in a test app.

  • seems like I can't load any kind of plugins! I wrote a simple plugin and a tester and tried to load it with QPluginLoader but the instance function always return null... :( reading the documentation didn't help me either!

  • Moderators

    Well there are a few possibilities that would cause that.

    1. You may have built your plugin with a version of Qt older than the one your app is built with. I doubt this is the problem but thought I'd mention it.

    2. You may have built a debug plugin and a release app, or vice versa. Make sure you match debug and release of plugins and application.

    3. You are loading your plugin wrong, I am adding some code to load a custom plugin explicitly:

    QDir pluginsDir(QApplication::applicationDirPath());"plugins"); // plugin path is /path/to/my/app/plugins

    // this loop loads all the plugins in the plugins dir
    foreach (QString filename, pluginsDir.entryList(QDir::Files))
    qDebug() << "Trying to load plugin: " << filename;
    QPluginLoader pl(pluginsDir.absoluteFilePath(filename));
    QObject *plugin = pl.instance();
    if (plugin)
    qDebug() << "Plugin loaded";
    qDebug() << "Failed to load plugin, error: " << pl.errorString();

    I typed out that code in this edit box so hopefully it's error free and compiles. :)

    Make sure you create a directory called plugins in your application launch directory and put your plugin(s) in there.

    For example:

    cd /my/app/path

    mkdir plugins

    ls -l

    Should show your app and the plugins dir.

    cp /path/to/my/plugin /my/app/path/plugins

    ls -l /my/app/path/plugins

    Should show your plugin in that directory.

    Run the example on the console so you can see the qDebug() results.

    I just realized I assumed a posix environment in my example commands, translate to windows if you are using that os.

  • Moderators

    Oh and 1 more super important thing, make sure you have the following in your plugin pro file:

    TEMPLATE = lib
    CONFIG += plugin

    EDIT: the above may not be true anymore. This might be old Qt4 knowledge rattling around in my head. It may still be required but I can't remember now. Also "here": is a good document on creating plugins you should read.

  • thanks. it worked!

Log in to reply