Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QVariant QTextBrowser::loadResource ( int  type,
const QUrl name 
) [virtual]

This function is called when the document is loaded and for each image in the document. The type indicates the type of resource to be loaded. An invalid QVariant is returned if the resource cannot be loaded.

The default implementation ignores type and tries to locate the resources by interpreting name as a file name. If it is not an absolute path it tries to find the file in the paths of the searchPaths property and in the same directory as the current source. On success, the result is a QVariant that stores a QByteArray with the contents of the file.

If you reimplement this function, you can return other QVariant types. The table below shows which variant types are supported depending on the resource type:

ResourceType QVariant::Type QTextDocument::HtmlResource QString or QByteArray QTextDocument::ImageResource QImage, QPixmap or QByteArray QTextDocument::StyleSheetResource QString or QByteArray

Reimplemented from QTextEdit.

Definition at line 1087 of file qtextbrowser.cpp.

References QFile::close(), QFile::open(), and QIODevice::readAll().

{
    Q_D(QTextBrowser);

    QByteArray data;
    QString fileName = d->findFile(d->resolveUrl(name));
    QFile f(fileName);
    if (f.open(QFile::ReadOnly)) {
        data = f.readAll();
        f.close();
    } else {
        return QVariant();
    }

    return data;
}


Generated by  Doxygen 1.6.0   Back to index