January 26, 2011

willypuzzle willypuzzle
Lab Rat
40 posts

Hidden information in a QTextDocument

 

Hello, I need to embed some information in a QTextDocument but it has to be hidden. A QTextEdit doesn’t have to show that information but it is only for my program purpose.
I saw there are MetaInformation but there are only two values, url and title. I need more and different values.
I think to make a fragment or a block hidden but I fear that user can edit above it or change its position so I can’t get it anymore.

Has someone some suggest form me?
Best Regards
Willy

6 replies

January 26, 2011

BlackDante BlackDante
Lab Rat
55 posts

Maybe you can create your own class that inherits QTextDocument, something like this:

  1. class MyEditor : public QTextDocument{
  2. Q_OBJECT
  3. public:
  4. MyEditor(QWidget *parent = 0);
  5. QString get_info();
  6. void set_info(const QString &info);
  7. private:
  8. QString info;
  9. };

 Signature 

sorry for my broken english :)

January 26, 2011

ngrosjean ngrosjean
Lab Rat
35 posts

You could just create a class that inherit QTextDocument, then use it. In your sub class just add a QString and do what you want with it.
Another solution on your subclass is to play with http://doc.trolltech.com/4.6.2/qobject.html#Q_PROPERTY and other Q_… macro.

January 26, 2011

willypuzzle willypuzzle
Lab Rat
40 posts

Interesting ideas, some idea to store and retrieve info on and from same document’s file?

January 26, 2011

habert habert
Lab Rat
1 posts

why not just use QObject::setProperty function

January 26, 2011

willypuzzle willypuzzle
Lab Rat
40 posts

My problem is storing and retrieving information from file on disk.

January 26, 2011

Volker Volker
Robot Herder
5428 posts

There are no means to leave comments or hidden text in a text document. You would have to subclass QTextDocument and/or QTextEdit an put that information into the output generated by that manually. You will have to parse it out of a to-be-set document manually too, as QTextDocument discards all data it is not supposed to use (ie. feeding your manually crafted text into a regular QTextDocument “cleans” out all the added data).

 
  ‹‹ What’s relationship between viewport(), widget() and QScrollArea      QNetworkAccessManager doesn’t download whole web page ››

You must log in to post a reply. Not a member yet? Register here!