for (quint32 t = 0 ; t <= (txt.size()/8) ; t = t+11 )
{
}
for (quint32 t = 0 ; t <= (txt.size()/8) ; t = t+11 )
{
txt.insert( t , QString(",0x"));
}
To copy to clipboard, switch view to plain text mode
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:
QString txt
= ui
->textEdit
->toPlainText
();
while (txt.isEmpty()==false) {
tmp << txt.left(8);
txt.remove(0,8);
}
ui->textEdit->setText(tmp.join(",0x"));
QString txt = ui->textEdit->toPlainText();
QStringList tmp;
while (txt.isEmpty()==false) {
tmp << txt.left(8);
txt.remove(0,8);
}
ui->textEdit->setText(tmp.join(",0x"));
To copy to clipboard, switch view to plain text mode
Bookmarks