Reputation: 385
I have a function which returns selected text only from qtextedit. I need to get plain text, but this function returns text with some control characters.
For example: function textEdit->textCursor().selectedText() return:
"select? timestamp,? strftime('%d.%m.%Y', Datetime(timestamp, 'unixepoch', 'localtime')) as date,? strftime('%H:%M:%S', Datetime(timestamp, 'unixepoch', 'localtime')) as time,? author,? from_dispname,? dialog_partner,? body_xml?from? Messages?where? timestamp >= 1501504199? -- timestamp >= 1502345001?order by? timestamp asc"
function textEdit->toPlainText() return:
"select\n timestamp,\n strftime('%d.%m.%Y', Datetime(timestamp, 'unixepoch', 'localtime')) as date,\n strftime('%H:%M:%S', Datetime(timestamp, 'unixepoch', 'localtime')) as time,\n author,\n from_dispname,\n dialog_partner,\n body_xml\nfrom\n Messages\nwhere\n timestamp >= 1501504199\n -- timestamp >= 1502345001\norder by\n timestamp asc"
In first example are ?(question mark) without enters and I am not able to replace them.
What am I doing wrong?
Upvotes: 2
Views: 1828
Reputation: 7146
To wrap the comments up as an answer:
As the documentation of QTextCursor::selectedText
states:
Note: If the selection obtained from an editor spans a line break, the text will contain a Unicode U+2029 paragraph separator character instead of a newline \n character. Use QString::replace() to replace these characters with newlines.
Which shows up as a ?
when shown in debug output. One can either use QString::replace
as stated in the documentation, or use QTextCursor::selection
instead (by using selection().toPlainText()
to get the text from the selection)
Upvotes: 7