Non static image plugin
-
wrote on 11 Jan 2012, 17:55 last edited by
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.
-
wrote on 12 Jan 2012, 01:14 last edited by
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.
-
wrote on 12 Jan 2012, 01:25 last edited by
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.
-
wrote on 12 Jan 2012, 02:01 last edited by
Hard to say anything without seeing some code.
-
wrote on 12 Jan 2012, 02:14 last edited by
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>QT_BEGIN_NAMESPACE
class MskPlugin : public QImageIOPlugin
{
public:
QStringList keys() const;
Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;private:
};
#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;
handler->setDevice(device);
handler->setFormat(format);
return handler;
}Q_EXPORT_PLUGIN2(mskPlugin, MskPlugin)
QT_END_NAMESPACE
@ -
wrote on 12 Jan 2012, 02:18 last edited by
The class declaration in the header file (.h) is missing the Q_OBJECT macro.
@
QT_BEGIN_NAMESPACEclass MskPlugin : public QImageIOPlugin
{
Q_OBJECT
public:
QStringList keys() const;
@ -
wrote on 12 Jan 2012, 02:59 last edited by
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
{
public:
QStringList keys() const;
Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;
};
@ -
wrote on 12 Jan 2012, 12:42 last edited by
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 :) )
-
wrote on 12 Jan 2012, 14:46 last edited by
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
-
wrote on 12 Jan 2012, 22:34 last edited by
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.?
-
wrote on 13 Jan 2012, 16:08 last edited by
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.
-
wrote on 13 Jan 2012, 16:13 last edited by
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 :)
-
wrote on 13 Jan 2012, 16:21 last edited by
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)
{
ui.setupUi(this);QString mskFp("...0012.msk");
QImage* mskImg = new QImage(mskFp);
QPixmap mskPmp = QPixmap::fromImage(*mskImg);
ui.mskImg->setPixmap(sMskPmp);
}QIMskTest::~QIMskTest()
{}
@ -
wrote on 13 Jan 2012, 16:54 last edited by
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.
-
wrote on 13 Jan 2012, 21:51 last edited by
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.
-
wrote on 13 Jan 2012, 22:21 last edited by
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.
-
wrote on 23 Mar 2012, 16:11 last edited by
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).Regards,
Nmut. -
wrote on 12 Jun 2013, 12:19 last edited by
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!
http://wordpress.org/extend/plugins/wp-flip-image-free
Thanks.