⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Non static image plugin

  • Has anyone been able to successfully create a previously unsupported image plugin type (i.e. not TIFF, JPG, GIFF, ICO, etc)?

    I ask because I believe there is a significant bug in the 'qmetaobject.cpp' kernel module.

  • If you refer to subclasses of [[Doc:QImageIOPlugin]], yes, these work. All the image format plugins delivered with Qt are based on this.

    If qmetaobject.cpp contained an error, I would suspect it to have popped up long before.

  • Well, all I can say is that I just created a plugin derived from QImageIOPlugin, and it;s DLL is found, and the 'keys' routine is called, but qmetaobject.cpp fails to recognize that it is a subclass of QImageIOPlugin. As a result, 'create' is never called, and it does not work.

  • Hard to say anything without seeing some code.

  • Alright. Here's the .h file:

    @#ifndef MSKPLUGIN_H
    #define MSKPLUGIN_H

    #include "mskplugin_global.h"
    #include "MskHandler.h"

    #include <qstringlist.h>
    #include <QImageIOPlugin>
    //#include <QtPlugin>


    class MskPlugin : public QImageIOPlugin
    QStringList keys() const;
    Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
    QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;



    #endif // MSKPLUGIN_H

    and the .cpp:

    @#include "mskplugin.h"

    QStringList MskPlugin::keys() const
    return QStringList() << QLatin1String("msk");

    QImageIOPlugin::Capabilities MskPlugin::capabilities(
    QIODevice *device, const QByteArray &format) const
    if (format == "msk")
    return Capabilities(CanRead);
    //return Capabilities(CanRead | CanWrite); Writing currently disabled.

    if (!(format.isEmpty() && device->isOpen()))
        return 0;
    Capabilities cap;

    if (device->isReadable() && device->peek(4) == "MSK2")
    cap |= CanRead;

    /* Currently, disable writing.
    if (device->isWritable())
    cap |= CanWrite;

    return cap;


    QImageIOHandler *MskPlugin::create(QIODevice *device, const QByteArray &format) const
    QImageIOHandler *handler = new MskHandler;
    return handler;

    Q_EXPORT_PLUGIN2(mskPlugin, MskPlugin)


  • The class declaration in the header file (.h) is missing the Q_OBJECT macro.


    class MskPlugin : public QImageIOPlugin
    QStringList keys() const;

  • Tried that; it had no effect. And, none of the example plugins have Q_OBJECT. For example, here's the plugin def for the 'ICO' file type:

    @class QICOPlugin : public QImageIOPlugin
    QStringList keys() const;
    Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
    QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;

  • The code looks ok so far. I just tried with my own plugin, it gets called and I don't get any errors (despite my actual read method not being implemented yet and thus returning and empty image :) )

  • Interesting. Can you give me some more info about your config? Version? iDE you used, What file type you defined, please. Mine is 4.7.4 64 bit and VS 2010

  • I'm using the Mac, Qt 4.8.0. But this shouldn't be a problem.

    Do you get any output on the console? Some warnings, etc.?

  • Yes, actually:

    QObject::moveToThread: Current thread (0x1f2a7b0) is not the object's thread (0x398450).
    Cannot move to target thread (0x1f2a7b0)

    Although, I cant, for the life of me, see how it relates.

  • So, you have threads involved. That complicates things.

    As a first step: Cut down your application to just the imageformat plugin and a very, very simple test application. No threads, no fancy GUI. Just a dialog containing a label and three lines to set an image on the label - setPixmap(QPixmap::fromImage(xxx)). Nothing more.

    If that works, move on to a bigger project. If not, feel free to come back here, of course :)

  • Ummm... Well first, I don't use threads in my app -- that's why the message seemed strange. And secondly, your suggestion is exactly where I am, now. Here is my app currently (minus the 'main.cpp which is the generic app startup for a single dialog):

    @#include "qimsktest.h"

    #include "qfileinfo.h"

    #include "qpluginloader.h"
    #include "qlibrary.h"
    #include "qimageiohandler.h"

    QIMskTest::QIMskTest(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)

    QString mskFp("...0012.msk");

    QImage* mskImg = new QImage(mskFp);

    QPixmap mskPmp = QPixmap::fromImage(*mskImg);




  • The moveToThread error message is caused by this code, at line 239 in 'qfactoryloader.cpp:

    @ obj->moveToThread(QCoreApplicationPrivate::mainThread());@

    Which, in turn is called by line 292 in qimagereader.cpp:

    @ QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(QString::fromLatin1(suffix)));

    It's trying to get a plugin pointer for my DLL class so it can call the 'create' method. The thread error causes the above line to return zero for 'plugin', and hence, none of my other plugin classes gets called.

  • Do you have another library in use which sneaks in the secondary thread? Do you load the plugin manually or do you leave it delegated to the image I/O system?

    My plugin is not yet ready to be published, so I cannot offer something to test and compare for you.

  • No, what you see is what I have. There's just the one form, with the single label on it. I have no other threads defined, and I don't use another library. I do not load the plugin manually; QT loads is automatically.

  • Hi guys

    Sorry to "up" this old thread...

    Steve, did you solve your problem?
    I have the same message with my custom image plugin. the only thing I had found is that there is some mismatch with Qt versions (4.7.4 and 4.8.0 installed...). And my plugin is nether recognised (QImageReader::supportedImageFormats does not return my image format).


  • Hello

    This fantastic Flip Image Plugin lets me design the back of my photo to complement the text I put there. It offers a great choice of colors and fonts. Way to go Flip Image!



Log in to reply