I am trying to use a QTextStream
to format numerical output. I've simplified my issue into a little test program to demonstrate my problem. Following is my code:
#include <QCoreApplication>
#include <QTextStream>
#include <QFile>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile file("testfile.txt");
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream out(&file);
out.setFieldAlignment(QTextStream::AlignLeft);
out.setFieldWidth(5);
out << "1" << "A" << endl;
out << "2" << "B" << endl;
out << "3" << "C" << endl;
out << "4" << "D" << endl;
out << "5" << "E" << endl;
out << "6" << "F" << endl;
}
return a.exec();
}
Here is the output generated by the above program:
1 A
2 B
3 C
4 D
5 E
6 F
Notice the indentation on the bottom five lines? That's my problem, is I don't want the indentation to start new lines. I want every line to begin at column 0, and to write a value that is five columns wide (my field width) and for it to be left-justified.
I've tried playing around with the parameters for sometime without luck. If I can get this to work in the little test program above, I think I can have success porting that change into my much larger program that writes a text file.