View Full Version : QTextStream not adding new line
hokie2012
16th September 2010, 22:18
I am trying to write to a buffer and then to the screen, i am using
]buffer << j.value() << "|" << j.key() << "\r\n";
i have tried
"\n"
'\n'
'\r\n'
<< endl
and none of them will add a new line..any ideas?
Lykurg
16th September 2010, 22:27
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QString str;
QTextStream stream(&str);
stream << "foo" << "\n" << "bar";
QLabel l(str);
l.show();
return app.exec();
}works as expected. If it also did for you, then anything other in your code is wrong...
hokie2012
16th September 2010, 22:32
what else would be wrong in my code that would effect simply adding a new line
Lykurg
16th September 2010, 22:37
Does it work for you or not? and where do you display the text? Maybe there new lines are ignored.
EDIT: Or do you convert it afterwards in some way?
hokie2012
16th September 2010, 22:39
QString message;
QTextStream buf(&message);
int count =0 ;
QMapIterator<int, QString> i(sortedFound);
i.toBack();
buf << "FOUND" << endl;
while (i.hasPrevious() && count < n)
{
i.previous();
buf << i.value() << "|" << i.key() << "\r\n";
count++;
}
QTextEdit label2(message);
label2.show();
is what i have that doesnt work
Lykurg
16th September 2010, 22:45
Here we go! By passing the text to the ctor QTextEdit interprets it as HTML. Therefore you see no newline. Use QTextEdit::setText() or use QPlainTextEdit if you don't need HTML.
hokie2012
16th September 2010, 22:50
YES! problem solved, thank you * 100000
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.