HTML String Question
-
Hello,
i have 2 variants of a HTML String:
QString tmpStr_tx = QString("<font color = \"red\"> %1 %2</font>").arg("ECW<< ").arg(ba2OutString(currMessage_tx)); ui->lvWidget->appendHtml(tmpStr_tx); QString tmpStr_tx = QString("<font color = \"red\"> %1 %2</font>").arg("<<ECW ").arg(ba2OutString(currMessage_tx)); ui->lvWidget->appendHtml(tmpStr_tx);
In lvWidget (QPlainTextEdit) only the part until occurence of "<<" is displayed.
1st: ECW and nothing else
2nd empty line with linefeedProblem seem sto be the 2 '<' in arg %1
How to form the html string to display "<<ECW " ?
Maybe something using "htmlspecialchars" but i do not know how to.
'<' (less than) becomes "<"
'>' (greater than) becomes ">" -
<
and>
are special characters in html so yes, you should use entities to display them. Second thing is - if you're passing a string literal as an argument why not embed it in the string in the first place?QString tmpStr_tx = QString("<font color = \"red\"> ECW<< %1</font>").arg(ba2OutString(currMessage_tx)); ui->lvWidget->appendHtml(tmpStr_tx);
-
why not embed it in the string ...
because text of arg1 is dependend on arg2.
The literal is for testing now, but will be replaced by a QStringvariable
generated above this line in next version.Thanks for the answer, hopefullyit will work in .arg( .... ) also.
Yup:QString tmpStr_tx = QString("<font color = \"red\"> %1 %2</font>").arg("<<ECW ").arg(ba2OutString(currMessage_tx));
-
@wally123 said:
hopefullyit will work in .arg( .... ) also.
It will. It's just constructing a string. The html parsing happens later, when you pass that string to
appendHtml()
.