how to display non-printable characters on QTextEdit
-
@addebito When exactly does it crash? When on_pushButton_clicked() is called? If so please set a break point at the first line in on_pushButton_clicked() and run through debugger, when debugger stops inside on_pushButton_clicked() execute line by line and see in which line it crashes.
-
@addebito
Apart from answering @jsulm about the "crash", which you should do.I'm not sure what it is you are trying to avoid iterating or expect to improve speed on. Your algorithm will be:
for each char in input string if 0 <= char <= 31 copy the 3-character "name" for char from table[indexed directly by char value] to new string else copy the original char unchanged to new string
You're not getting to get anything more much more efficient than that.
-
@jsulm it crashes when the code reach this line
ui->textEdit->setDocument(doc);
...or if I uncomment the second line, that was the first version without QTextDocument ...
ui->textEdit->setText(c);
...so, in both case, when I put the text into QTextEdit
-
@JonB said in how to display non-printable characters on QTextEdit:
I'm not sure what it is you are trying to avoid iterating or expect to improve speed on. Your algorithm will be:
You're not getting to get anything more much more efficient than that.
Thank you @JonB.
My goal is only to explorer, as always when I have a little time to investigate, a better solution.
Never give up! ;-) -
@addebito
if thisvoid MainWindow::on_pushButton_clicked() { QChar c = 2; // ui->textEdit->setText(c); QTextDocument *doc = new QTextDocument; doc->setPlainText(QString(c) + "this is a tab"); QTextOption opt; opt.setFlags(QTextOption::ShowTabsAndSpaces); doc->setDefaultTextOption(opt); ui->textEdit->setDocument(doc); }
is your function, then where is your replace operation ?
-
@J-Hilk this is only a demo to reproduce the same error, when the software has to print on QTextEdit some non printable chars, it crashes.
I've tried these chars
1 = SOH
2 = STX
3 = ETX
4 = EOT
5 = ENQQChar c = 1; ui->textEdit->setText(c);
If you try to print these chars on QTextEdit your application doesn't crash ??
-
@addebito said in how to display non-printable characters on QTextEdit:
If you try to print these chars on QTextEdit your application doesn't crash ??
I don't understand: didn't you want to convert these chars to something printable?
-
@jsulm said in how to display non-printable characters on QTextEdit:
I don't understand: didn't you want to convert these chars to something printable?
Yes @jsulm and I'm looking for a different solution instead a for cycle iteration, but the discussion is getting longer than expected, so I'll adopt this one, I'll check every single char.
Thank you so much for all the advice and for your time.