window7下QT;目的是让QTextStream写文本时能够自动换行
代码如下 :这是在window7下QT的;目的是让QTextStream 中能够自动换行,但尝试了半天,平常编程中的<<\n <<\t <<"\n" <<"\t" <<endl 都是不行的。摸索了半天,最后在qt 的help中找到了原因:
在Windows上,所有写成“\n”字符要写成“\r\n”<<<<
if (file.open(QFile::WriteOnly | QFile::Truncate))
{
QTextStream ou(&file);
ou << "Result: "
<< "\n" <<"1"
<< left<<"2"
<< endl<<ui->lineEdit_2->text().toStdString().data()
<< "\n"<<"3"
<<TI.date().toString("yyyyMMdd")
<<"\n"<<"4"
<<tii.currentTime().toString("hhmm")//上面这些换行都没有实现!!!!!!!!!!
<<endl<< "\r\n"<< qSetFieldWidth(10)
<<"OVER";//:在Windows上,所有写成“\ n”字符“\ r \ n”这里可以换行!!!!!!!!!!
原文:
QTextStream & endl(QTextStream & stream)
Writes '\n' to the stream and flushes the stream. Equivalent to
stream <</SPAN><</SPAN> '\n' <</SPAN><</SPAN> flush;
Note: On Windows, all '\n' characters are written as '\r\n' if QTextStream's device or string is opened using the QIODevice::Text flag.