QImageIOPlugin Class

The QImageIOPlugin class defines an interface for writing an image format plugin. More...

Header: #include <QImageIOPlugin>
qmake: QT += gui
Inherits: QObject.

Note: All functions in this class are reentrant.

Public Types

flags Capabilities
enum Capability { CanRead, CanWrite, CanReadIncremental }

Public Functions

QImageIOPlugin(QObject * parent = 0)
virtual ~QImageIOPlugin()
virtual Capabilities capabilities(QIODevice * device, const QByteArray & format) const = 0
virtual QImageIOHandler * create(QIODevice * device, const QByteArray & format = QByteArray()) const = 0
  • 31 public functions inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 2 signals inherited from QObject
  • 11 static public members inherited from QObject
  • 9 protected functions inherited from QObject

Detailed Description

The QImageIOPlugin class defines an interface for writing an image format plugin.

QImageIOPlugin is a factory for creating QImageIOHandler objects, which are used internally by QImageReader and QImageWriter to add support for different image formats to Qt.

Writing an image I/O plugin is achieved by subclassing this base class, reimplementing the pure virtual functions capabilities() and create(), and exporting the class with the Q_PLUGIN_METADATA() macro. See How to Create Qt Plugins for details.

An image format plugin can support three capabilities: reading (CanRead), writing (CanWrite) and incremental reading (CanReadIncremental). Reimplement capabilities() in you subclass to expose the capabilities of your image format.

create() should create an instance of your QImageIOHandler subclass, with the provided device and format properly set, and return this handler.

The json metadata file for the plugin needs to contain information about the image formats the plugins supports, together with the corresponding MIME types (one for each format). For a jpeg plugin, this could, for example, look as follows:

{
  "Keys": [ "jpg", "jpeg" ],
  "MimeTypes": [ "image/jpeg", "image/jpeg" ]
}

Different plugins can support different capabilities. For example, you may have one plugin that supports reading the GIF format, and another that supports writing. Qt will select the correct plugin for the job, depending on the return value of capabilities(). If several plugins support the same capability, Qt will select one arbitrarily.

See also QImageIOHandler and How to Create Qt Plugins.

Member Type Documentation

enum QImageIOPlugin::​Capability
flags QImageIOPlugin::​Capabilities

This enum describes the capabilities of a QImageIOPlugin.

ConstantValueDescription
QImageIOPlugin::CanRead0x1The plugin can read images.
QImageIOPlugin::CanWrite0x2The plugin can write images.
QImageIOPlugin::CanReadIncremental0x4The plugin can read images incrementally.

The Capabilities type is a typedef for QFlags<Capability>. It stores an OR combination of Capability values.

Member Function Documentation

QImageIOPlugin::​QImageIOPlugin(QObject * parent = 0)

Constructs an image plugin with the given parent. This is invoked automatically by the moc generated code that exports the plugin.

[virtual] QImageIOPlugin::​~QImageIOPlugin()

Destroys the picture format plugin.

You never have to call this explicitly. Qt destroys a plugin automatically when it is no longer used.

[pure virtual] Capabilities QImageIOPlugin::​capabilities(QIODevice * device, const QByteArray & format) const

Returns the capabilities of the plugin, based on the data in device and the format format. If device is 0, it should simply report whether the format can be read or written. Otherwise, it should attempt to determine whether the given format (or any format supported by the plugin if format is empty) can be read from or written to device. It should do this without changing the state of device (typically by using QIODevice::peek()).

For example, if the QImageIOPlugin supports the BMP format, format is either empty or "bmp", and the data in the device starts with the characters "BM", this function should return CanRead. If format is "bmp", device is 0 and the handler supports both reading and writing, this function should return CanRead | CanWrite.

Format names are always given in lower case.

[pure virtual] QImageIOHandler * QImageIOPlugin::​create(QIODevice * device, const QByteArray & format = QByteArray()) const

Creates and returns a QImageIOHandler subclass, with device and format set. The format must come from the values listed in the "Keys" entry in the plugin metadata, or be empty. If it is empty, the data in device must have been recognized by the capabilities() method (with a likewise empty format).

Format names are always given in lower case.

© 2015 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.