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 (!file.open(QFile::ReadOnly))
        return false;
    
    QByteArray data = file.readAll();
    QTextCodec *codec = Qt::codecForHtml(data);
    QString str = codec->toUnicode(data);
    if (Qt::mightBeRichText(str)) {
        textEdit->setHtml(str);
    } else {
        str = QString::fromLocal8Bit(data);
        textEdit->setPlainText(str);
    }
    //// mypath is the directory to the image file
    #ifdef Q_OS_WIN
        textEdit->document()->setMetaInformation( QTextDocument::DocumentUrl, mypath + "/" );
        qDebug()<<"checked";
    #else
        textEdit->document()->setMetaInformation( QTextDocument::DocumentUrl, "file:" + mypath + "/");
    #endif
    ////
    setCurrentFileName(f);
    return true;
    }

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.