Strange QTextDocument behavior



  • My Windows desktop app monitors QTextDocument's contentsChange(int,int,int) method. If you type a letter into a blank document, that method announces 0 characters deleted and 1 inserted - which is the expected behavior. However, if you paste any text at the beginning of the document, it announces that ALL + 1 of the characters have been deleted and that all have been inserted.

    For example:
    If the document contains "abc" and you paste "123" at the beginning it announces 4 deleted and 6 inserted.



  • Yup,
    Very understandable. If you load a file, you just can't write to the beginning of the file. The file will be in sequence. So to "paste" the letters you want the file needs to be stored in RAM, cleared from driver and rewritten from RAM.
    Only when appending the data to the end of the file you will get the 3 chars added.
    greetz



  • Jeroentje, QTextDocument is not a file. It's used by text components. Why would the behavior of pasting a single letter at the beginning be different from typing one?

    Typing a single letter before "abc" results in 0 deleted 1 added.
    Pasting a single letter before "abc" results in 4 deleted 4 added.



  • You should file a bug report, as this doesn't seem like the intended behaviour, also judging from the documentation of the signal.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.