(求助)Qt下换行问题
qt吧
全部回复
仅看楼主
level 5
yanglutqs
楼主
尝试使用QIODevice::Text函数,还有QTextStream函数输出“output.txt”
使用out<<endl;
out<<“\r\n”;
out<<“\n”;
out<<“\r\n”<<endl;
换行都失败,求解。。。。
2012年06月10日 03点06分
1
level 8
fcwlxd
QFile file("output.txt");
QStream out(&file);
out<<"i"<<endl<<"fsck"<<endl<<"the"<<"faidu"<<endl;
2012年06月10日 04点06分
2
level 8
fcwlxd
很奇怪,用QIODevice::Text打不开文件,也创建不了。ReadWrite正常,因为不是windows的绿故?
2012年06月10日 04点06分
3
level 9
jingyingbox
这个是描述目标是文本文件,用来转换换行符的
QIODevice::ReadWrite 是描述既可读又可写的
两者不冲突啊,可以用按位或(|)叠加到一起啊
2012年06月10日 05点06分
4
level 5
yanglutqs
楼主
看你这写的应该是
i
fsck
the
...
都有分行吧,结果都是一条直线。。。
不好使啊 同学。。。
void YaunLayoutWidget::setFile(){ QFile data("output.txt"); if (data.open(QFile::WriteOnly | QFile::Truncate)) { QTextStream out(&data); //title out << "Row: " << qSetFieldWidth(10) << left << spinBox4->value() ; out << "Column: " << qSetFieldWidth(10) << left << spinBox5->value() ; out << "Width: " << qSetFieldWidth(10) << left << spinBox1->value() ; out << "Length: " << qSetFieldWidth(10) << left << spinBox2->value() ; out << "Spaciing: " << qSetFieldWidth(10) << left << spinBox3->value(); //blank// out<<endl; //cells define out<<"i"<<endl<<"fsck"<<endl<<"the"<<"faidu"<<endl;// out<<left <<"1"<<" " << "1 " << "-7.9 " << "-1 2 -3" <<"\r\n";// out<<"Thomas M. disch: " << 334 << endl;// out<<"Thomas M. disch: " << 334 << endl; data.close(); }}
2012年06月10日 08点06分
5
level 5
yanglutqs
楼主
void YaunLayoutWidget::setFile()
{
QFile data("output.txt");
if (data.open(QFile::WriteOnly | QFile::Truncate))
{
QTextStream out(&data); //title
out << "Row: " << qSetFieldWidth(10) << left << spinBox4->value() ;
out << "Column: " << qSetFieldWidth(10) << left << spinBox5->value() ;
out << "Width: " << qSetFieldWidth(10) << left << spinBox1->value() ;
out << "Length: " << qSetFieldWidth(10) << left << spinBox2->value() ;
out << "Spaciing: " << qSetFieldWidth(10) << left << spinBox3->value();
out<<"i"<<endl<<"fsck"<<endl<<"the"<<"faidu"<<endl;
data.close();
}
}
2012年06月10日 08点06分
6
level 8
fcwlxd
2012年06月10日 09点06分
7
level 9
jingyingbox
windows和linux不一样的....
2012年06月10日 13点06分
8
level 7
此方的呆毛
只是用QIODevice::Text?
如果需要写的话,还需要QIODevice::WriteOnly这类。
另外,没必要使用'\r\n',直接用'\n'就可以了,都已经用文本模式打开了,IO流会自己完成转换的。
没记错的话。
2012年06月10日 15点06分
9
level 9
jingyingbox
回复9楼:正解
2012年06月10日 16点06分
10
level 7
noodlest
这个东西我也一直搞不清楚。比较模棱两可,我一般是只使用'\n'的。
2012年06月11日 00点06分
11
level 5
yanglutqs
楼主
终于搞定了 谢谢 呵呵
2012年06月11日 05点06分
12
烤哥尔
怎么搞定的,我快急死了
2017年12月06日 01点12分
烤哥尔
教我一下谢谢
2017年12月06日 03点12分
heluozhijian
很常见的**做法,一群人讨论一个问题,有人搞定了就丢一句“搞定了”,也不说怎么搞定的;要么是新手没经验,要么就是自私自利不懂分享。
2019年02月19日 06点02分
level 5
点击注销用户
http://blog.csdn.net/u012689588/article/details/19431353
2014年02月18日 14点02分
14
level 11
chr1999
指定text,会自己转换
2014年02月18日 14点02分
15
level 7
wxh102261
我也在弄这个,你告诉一下怎么弄得么
2017年05月11日 09点05分
16
1