Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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]


  • Lifetime Qt Champion

    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/bpV8hgkC

    http://pastebin.com/jcdQgw4c

    I think read and canRead are put in properly.



  • Here I also uploaded the whole source.

    http://www.file-upload.net/download-10397238/ARGB2.zip.html


  • Lifetime Qt Champion

    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.


  • Lifetime Qt Champion

    Do you mean get the data from an OpenEXR image in QImage or use the plugin ?



  • yes, basically I want to load an OpenEXR image in QImage. The format is not supported. Therefore I wanted to use the plugin.


  • Lifetime Qt Champion

    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?


  • Lifetime Qt Champion

    Yes, you will need to convert your EXR images in something supported by QImage


Log in to reply