Nominate our 2022 Qt Champions!

document()->setMetaInformation does not work

  • In the Qt TextEdit example, there is a load function as below. It does not work as I insert image to the document(??), by doing "cursor.insertImage(imageFormat);", after some searching I added the code of setMetaInformation between the "////" mark (confirmed the setMetaInformation should be executed.). However it still does not work and the image is not displayed. The image will show if opening such html in web browser. What am I missing? Thank you.

    bool TextEdit::load(const QString &f)
    if (!QFile::exists(f))
        return false;
    QFile file(f);
    if (!
        return false;
    QByteArray data = file.readAll();
    QTextCodec *codec = Qt::codecForHtml(data);
    QString str = codec->toUnicode(data);
    if (Qt::mightBeRichText(str)) {
    } else {
        str = QString::fromLocal8Bit(data);
    //// mypath is the directory to the image file
    #ifdef Q_OS_WIN
        textEdit->document()->setMetaInformation( QTextDocument::DocumentUrl, mypath + "/" );
        textEdit->document()->setMetaInformation( QTextDocument::DocumentUrl, "file:" + mypath + "/");
    return true;

Log in to reply