Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QAbstractFileEngineHandler Class Referenceabstract

\inmodule QtCore \reentrant More...

#include <qabstractfileengine_p.h>

+ Inheritance diagram for QAbstractFileEngineHandler:
+ Collaboration diagram for QAbstractFileEngineHandler:

Public Member Functions

 QAbstractFileEngineHandler ()
 Constructs a file handler and registers it with Qt.
 
virtual ~QAbstractFileEngineHandler ()
 Destroys the file handler.
 
virtual std::unique_ptr< QAbstractFileEnginecreate (const QString &fileName) const =0
 If this file handler can handle fileName, this method creates a file engine and returns it wrapped in a std::unique_ptr; otherwise returns nullptr.
 

Detailed Description

\inmodule QtCore \reentrant

The QAbstractFileEngineHandler class provides a way to register custom file engines with your application.

Since
4.1

QAbstractFileEngineHandler is a factory for creating QAbstractFileEngine objects (file engines), which are used internally by QFile, QFileInfo, and QDir when working with files and directories.

When you open a file, Qt chooses a suitable file engine by passing the file name from QFile or QDir through an internal list of registered file engine handlers. The first handler to recognize the file name is used to create the engine. Qt provides internal file engines for working with regular files and resources, but you can also register your own QAbstractFileEngine subclasses.

To install an application-specific file engine, you subclass QAbstractFileEngineHandler and reimplement create(). When you instantiate the handler (e.g. by creating an instance on the stack or on the heap), it will automatically register with Qt. (The latest registered handler takes precedence over existing handlers.)

For example:

{
public:
std::unique_ptr<QAbstractFileEngine> create(const QString &fileName) const override;
};
std::unique_ptr<QAbstractFileEngine> ZipEngineHandler::create(const QString &fileName) const
{
// ZipEngineHandler returns a ZipEngine for all .zip files
if (fileName.toLower().endsWith(".zip"_L1))
return std::make_unique<ZipEngine>(fileName);
return {};
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
window.show();
return app.exec();
}

When the handler is destroyed, it is automatically removed from Qt.

The most common approach to registering a handler is to create an instance as part of the start-up phase of your application. It is also possible to limit the scope of the file engine handler to a particular area of interest (e.g. a special file dialog that needs a custom file engine). By creating the handler inside a local scope, you can precisely control the area in which your engine will be applied without disturbing file operations in other parts of your application.

See also
QAbstractFileEngine, QAbstractFileEngine::create()

Definition at line 192 of file qabstractfileengine_p.h.

Constructor & Destructor Documentation

◆ QAbstractFileEngineHandler()

QAbstractFileEngineHandler::QAbstractFileEngineHandler ( )

Constructs a file handler and registers it with Qt.

Once created this handler's create() function will be called (along with all the other handlers) for any paths used. The most recently created handler that recognizes the given path (i.e. that returns a QAbstractFileEngine) is used for the new path.

See also
create()

Definition at line 112 of file qabstractfileengine.cpp.

References qt_file_engine_handlers_in_use.

◆ ~QAbstractFileEngineHandler()

QAbstractFileEngineHandler::~QAbstractFileEngineHandler ( )
virtual

Destroys the file handler.

This will automatically unregister the handler from Qt.

Definition at line 123 of file qabstractfileengine.cpp.

References QList< T >::isEmpty(), qt_abstractfileenginehandlerlist_shutDown, qt_file_engine_handlers_in_use, and QList< T >::removeOne().

+ Here is the call graph for this function:

Member Function Documentation

◆ create()

std::unique_ptr< QAbstractFileEngine > QAbstractFileEngineHandler::create ( const QString & fileName) const
pure virtual

If this file handler can handle fileName, this method creates a file engine and returns it wrapped in a std::unique_ptr; otherwise returns nullptr.

Example:

std::unique_ptr<QAbstractFileEngine> ZipEngineHandler::create(const QString &fileName) const
{
// ZipEngineHandler returns a ZipEngine for all .zip files
if (fileName.toLower().endsWith(".zip"_L1))
return std::make_unique<ZipEngine>(fileName);
else
return {};
}
See also
QAbstractFileEngine::create()

Implemented in QIOSFileEngineFactory, ZipEngineHandler, AndroidContentFileEngineHandler, AndroidAssetsFileEngineHandler, and QQmlPreviewFileEngineHandler.


The documentation for this class was generated from the following files: