PDA

View Full Version : QTextDocument removing resources?



MorrisLiang
9th October 2010, 11:26
QTextDocument* myTextDoc = myTextBrowser->document();
myTextDoc->addResource(QTextDocument::ImageResource,QUrl("relatedImage.jpg"),QVariant(relatedImg));

I'm trying to show a QPixmap in a QTextBrowser. I add the QPixmap relatedImg as a resource of the QTextDocument. Then I call QTextBrowser::setHtml("<img src='relatedImage.jpg'/>") to show it.

It works. But here're some questions.
1. Does QVariant(relatedImg) makes a full copy of the relatedImg?
2. How can I remove that resource when I don't need to show it anymore?
3. If relatedImg is updated (its content changed), do I need to call

myTextDoc->addResource(QTextDocument::ImageResource,QUrl("relatedImage.jpg"),QVariant(relatedImg)); again?

Lykurg
9th October 2010, 12:01
1. Does QVariant(relatedImg) makes a full copy of the relatedImg?
Yes. (...but no, since QPixmap uses Implicit Sharing. It will be copied if you alter the pixmap.)

2. How can I remove that resource when I don't need to show it anymore?
I guess by setting an emtpy QValue.

3. If relatedImg is updated (its content changed), do I need to call

myTextDoc->addResource(QTextDocument::ImageResource,QUrl("relatedImage.jpg"),QVariant(relatedImg)); again?
Guess so. Try it.

MorrisLiang
9th October 2010, 12:16
Thanks for the reply~