Building a Qt Image Plugin throws "invalid new-expression of abstract class type 'ArgbHandler'" error
-
Hi,
i tried to compile a QT Image Plugin. I used the tutorial here. But it is quite old. And I cannot find a new version.http://doc.qt.digia.com/qq/qq17-imageio.html
Here are the code snippets that belongs to the error message:
class ArgbPlugin : public QImageIOPlugin { QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const; }; QImageIOHandler *ArgbPlugin::create( QIODevice *device, const QByteArray &format) const { QImageIOHandler *handler = new ArgbHandler; handler->setDevice(device); handler->setFormat(format); return handler; } class ArgbHandler : public QImageIOHandler { public: ArgbHandler(); ~ArgbHandler(); // some methods are following.... };
Maybe someone can give me a hint.
I dont know how to append a file here in the forum. I could also send the whole qt project.
I am using QT 5.4.1 ,QT Creator 3.3.1 on windows 7 64 bit.
[edit: added missing coding tags SGaist]
-
Hi and welcome to devnet,
Did you implement both read and canRead in ArgbHandler ?
-
Hi,
thanks for your help. :)I will put the code to pastbin so it is easier to read.
http://pastebin.com/8hc1Fv5g
http://pastebin.com/DGxztH81
http://pastebin.com/DuRkrkva
http://pastebin.com/bpV8hgkCI think read and canRead are put in properly.
-
Here I also uploaded the whole source.
-
canRead is not implemented nor called properly
It isn't a static function (which you can't override by the way)
bool ArgbHandler::canRead() const { return device()->peek(4) == "\xCA\xFE\x12\x34"; }
class ArgbHandler : public QImageIOHandler { public: ArgbHandler(); ~ArgbHandler(); bool read(QImage *image); bool write(const QImage &image); bool canRead() const; QVariant option(ImageOption option) const; void setOption(ImageOption option, const QVariant &value); bool supportsOption(ImageOption option) const; };
which builds properly, however, I haven't done any run tests. You would also need to correct ArgbPlugin::capabilities for your plugin to build properly
-
Hi,
thanks for your quick answer.I could also compile it. My intension for the plugin was to get support for the OpenEXR file format in qt. I compiled the OpenEXR libs but i have not found a good tutorial how to finally connect them with the compiled plugin so I can load exr files as a QImage.
-
Do you mean get the data from an OpenEXR image in QImage or use the plugin ?
-
Sorry, I meant, do you have problem getting the plugin to load ? Or do you have problem to read images from an OpenEXR file ?
-
The plugin is loading correctly. I created a new simple QT app there i created a QImage.
I add the plugin via: QCoreApplication::addLibraryPath("some_path/plugins");
The app runs without an error.
But my problem is how can read an Open EXR image now. I guess I have to include the Openexr libs and use some special code for exr?
-
Yes, you will need to convert your EXR images in something supported by QImage