[英]how to write “<” in HTML contained in a QString for a QTextEdit widget
我是 QT 的新手。 我正在为“ C++ class 生成器”编写代码。 我正在从主要 window 中引入的数据生成 QString,以将其放入第二个 window 中的 QTextEdit 小部件中。 我在我的 QString“Generated_code”中使用了一些 HTML 代码。 问题是,当我介绍“<”字符时,它被认为是 HTML 标记,因此它没有显示在结果文本中。 那么我该如何编写这个字符并继续在我的 QString 中使用 HTML (因为还有另一个解决方案是在不使用任何 HTML 代码的情况下编写 QString )?
我在结果文本中得到了什么... ....一些文本包括 header1> 包括 header2>... 等等一些其他文本
void MainWindow::OpenDialogWindow()
{
....some other code
// a part of where i'm actually constructing the QString (MainWindow class methode)
if(!m_headers->itemText(0).isEmpty())
{
for(int i = 0 ; i < m_headers->count() ; i++)
{
Generated_code += "<br>#include <><<>" + m_headers->itemText(i) + "<>><></br>";
}
}
.
.
.
..... some other code
m_codeGenerated_Window = new CodeGeneratedWindow(Generated_code);
m_codeGenerated_Window->exec();
}
// the constructor of the second window
CodeGeneratedWindow::CodeGeneratedWindow(QString text)
{
m_diagLayout = new QVBoxLayout(this);
m_text = new QTextEdit();
m_text->setText(text);;
.... some code
}
您可能会执行以下操作:
for(int i = 0 ; i < m_headers->count() ; i++)
{
const auto cCode = QString("#include <%1>").arg(m_headers->itemText(i));
Generated_code += QString("<br>%1</br>").arg(cCode.toHtmlEscaped());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.