How to add newline to a QString?
-
Yes , "\n" works with QString , you can try the following code
@ QMessageBox::critical(this,"error","This \n is \n an \n error \n string !!!!!");@
that shows an error dialog like :
!http://img814.imageshack.us/img814/6962/capturelaa.png(error!!!)!
-
\n works when rendered as plain text, <br> works when rendered as html (textFormat: Text.StyledText)
\n is ignored when rendered as html, <br> is rendered as those 4 characters when rendered as plain text -
@BrianDavis said in How to add newline to a QString?:
\n works when rendered as plain text, <br> works when rendered as html (textFormat: Text.StyledText)
\n is ignored when rendered as html, <br> is rendered as those 4 characters when rendered as plain text\n works. Thanks @BrianDavis for sharing.
My code:QStringList strs; strs.append("Toyota"); strs.append("BUICK"); strs.append("VW"); strs.append("Mazda"); QFile p("car.txt"); if (p.open(QFile::WriteOnly | QIODevice::Text)) { QTextStream s(&p); for(QString line : strs){ s << line << "\n"; } }
-
@Jimmy-Crab hi and welcome to devnet,
QStringList::join would be simpler.