Important: Please read the Qt Code of Conduct -

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

  • Maybe you can create your own class that inherits QTextDocument, something like this:
    @class MyEditor : public QTextDocument{
    MyEditor(QWidget *parent = 0);
    QString get_info();
    void set_info(const QString &info);
    QString info;

  • 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 and other Q_... macro.

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

  • why not just use QObject::setProperty function

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

  • 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).

Log in to reply