How to manipulate a text in QTextEdit
Hi folk!
I'm trying to make a program to manipulate a text in a QTextEdit and show it after changes in the QTextEdit again. the first problem is that I'm completely newbie. the data is this:
Code:
00000000000000000000000000000000FEFFFF01FEFFFF03FFFFFF07FFFFFF070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080070F0080071F00C007FFFFFF07FFFFFF03FEFFFF03FCFFFF010000000000000000000000000000000000000000
00000000000000000000000000000000FFFFFF07FFFFFF07FFFFFF07FFFFFF07000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000FE0FF070FF0FF070FF0FF070FF0FF070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070F788007FF7F8007FF7F8007FE3F8007FC1F80070000000000000000000000000000000000000000
000000000000000000000000000000000FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF8C007FFFFFF07FFFFFF07FEFFFF03FCFFFF010000000000000000000000000000000000000000
00000000000000000000000000000000FF3F0000FF7F0000FF7F0000FF7F0000007800000078000000780000007800000078000000780000007800000078000000780000007800000078000000780000007800000078000000780000FFFFFF07FFFFFF07FFFFFF07FFFFFF070000000000000000000000000000000000000000
00000000000000000000000000000000FF3F8007FF7F8007FF7F8007FF7F80070F7880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF8C0070FF0FF070FF0FF070FF0FF030FC0FF010000000000000000000000000000000000000000
00000000000000000000000000000000FCFFFF01FEFFFF03FFFFFF07FFFFFF070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF8C0070FF0FF070FF0FF070FF0FF030FC0FF010000000000000000000000000000000000000000
000000000000000000000000000000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000001F000000FFFFFF07FFFFFF07FEFFFF07FCFFFF070000000000000000000000000000000000000000
00000000000000000000000000000000FCFFFF01FEFFFF03FFFFFF07FFFFFF070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880071FF8C007FFFFFF07FFFFFF07FEFFFF03FCFFFF010000000000000000000000000000000000000000
00000000000000000000000000000000FC3F8007FE7F8007FF7F8007FF7F80070F7880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF880070FF8C007FFFFFF07FFFFFF03FEFFFF03FCFFFF010000000000000000000000000000000000000000
the scenario is this:
When I put the data(above data) in the QTextEdit and push the button, the program put this string ",0x" after each 8 character. somthings like this:
Code:
000000000,0x000000000,0x00000000,0x0000000F,0xEFFFF01F,0xEFFFF03F,...
and show it on the QTextEdit.(replace)
I need to a simple guidance.
Re: How to manipulate a text in QTextEdit
That's not really related to QTextEdit, just basic string manipulation.
http://doc.qt.io/qt-5/qstring.html#insert
Cheers,
_
Re: How to manipulate a text in QTextEdit
Quote:
Originally Posted by
anda_skoa
Thanks!
that works but not correctly! :( look:
http://upload.tehran98.com/upme/uplo...818270e821.png
as you can see, after several insert, it cannot put ",0x" string anymore. why? the code is this:
Code:
void MainWindow::on_pushButton_clicked()
{
QString txt
= ui
->textEdit
->toPlainText
();
for (quint32 t = 0 ; t <= (txt.size()/8) ; t = t+11 )
{
}
ui->textEdit->setText(txt);
}
Re: How to manipulate a text in QTextEdit
Code:
for (quint32 t = 0 ; t <= (txt.size()/8) ; t = t+11 )
{
}
You are comparing the count of characters (stored in "t" and moved by 11 positions on each iteration) with the number of "octets" in the string. The former will always be greater and the loop will end sooner than you expect.
Look at this simple example with the string "0123456789abcdef" (16 chars):
iteration 0:
t=0, string = "0123456789abcdef"
t <= 2 ? true
iteration 1:
t=11, string = ",0x0123456789abcdef"
t <= (19/8) ? false
IMHO this would be a lot easier this way:
Code:
QString txt
= ui
->textEdit
->toPlainText
();
while (txt.isEmpty()==false) {
tmp << txt.left(8);
txt.remove(0,8);
}
ui->textEdit->setText(tmp.join(",0x"));