How to serialize and deserialize rich text in QTextEdit?

后端 未结 3 1270
面向向阳花
面向向阳花 2020-12-21 05:40

Say I have a structure like this:

class AAA
{
    BBB      bb_member;
    double   dbl_member;
    ....................
}

class BBB
{
    int             in         


        
3条回答
  •  醉话见心
    2020-12-21 06:00

    I have already compleated this task. I have saved the images in a QVector. Serialized the vector and the HTML code. Then deserialized the code and the QVector. Added all the images as a resource with this function:

    for(int i = 0; i < vectorOfImages.size(); i++ )
    {
        QUrl url(QString("image_%1").arg(i));
        textEdit->document()->addResource(QTextDocument::ImageResource, url,  vectorOfImages.at(i));
    }
    

    Then Does the following

    int count = 0;
    int pos = 0;
    
    QRegExp rx("");
    while ((pos = rx.indexIn(htmlCode, pos)) != -1)
    {
        QString strToReplace(QString("").arg(count));
        htmlCode.replace(pos, rx.matchedLength(), strToReplace);
        pos += rx.matchedLength();
        count++;
    }
    
    textEdit->setText(htmlCode);
    

    Works fine! And I will have my former rating :)))!

提交回复
热议问题