PDA

View Full Version : Saving images from QTextEdit



borges
9th January 2007, 10:38
Hello all,
I'm new to Qt and trying to build a simple text editor with support to inline images using QTextEdit.

I am using toHtml and setHtml to load and save text content, but i also need to save images (ideally together with text, for example in a zipped file). I looked in Qt API, but it doesn't seem to be a method to access image data contained in a document.

My idea is to save image content in a data structure (maybe a QHash) when user inserts a new image using the corresponding dialog and then using this data when saving the document. But what if an image gets inserted and then removed using backspace? Should I scan the entire document to see if some image has been removed, just before saving?
Is there a better way of doing this?

Thanks in advance,
Flavio

guilugi
9th January 2007, 17:33
Hello,

I think storing your image references in a QHash might be good, but you should only store references and not the images themselves...
Only during the saving process, you should include them in your archive.

And if the user deletes an image, you don't have to parse all the document.
First, you should work on the QTextDocument object, contained in QTextEdit (you can have the pointer with document()).

Then, simply catch the contentsChange(...) signal from document, it gives you position and informations about the changes...

Here's the doc for QTextDocument : http://doc.trolltech.com/4.1/qtextdocument.html

Just my 2 cent...I haven't tried it myself :)

borges
11th January 2007, 10:38
Just my 2 cent...I haven't tried it myself :)

Thanks, I'll try to implent it...