ChasW
31st January 2007, 22:06
I recently just installed qt-win-opensource-4.2.2 with the mingw compiler to try out a simple Qt app under Windows XP that I wrote under Linux.
I think I may have stumbled across a bug, but I am not certain. This minimal program demonstrates what I am observing.
#include <QString>
#include <QMessageBox>
#include <QApplication>
#include <string>
#include <fstream>
using std::endl;
using std::string;
using std::ifstream;
using std::ofstream;
using std::streamsize;
int main (int argc, char* argv[])
{
QApplication app (argc, argv);
ofstream OF;
OF.open("testdata.txt");
for (int i = 1; i <= 10; ++i)
{
OF << "test line " << i << endl;
}
OF.close();
ifstream IF;
IF.open("testdata.txt");
string line;
streamsize pos;
while (IF.good())
{
getline (IF, line);
IF.peek();
pos = IF.tellg();
QMessageBox::information(0, "line", QString::fromStdString(line));
}
IF.close();
return 0;
}
Under Linux the code works as expected. i.e it saves 10 lines to a file then reads the file one line at a time printing the contents of each line in a message box.
..but under Windows, using the mingw compiler and qt library, the contents of the string are altered such that only offset portions of the string are being read and printed to the message box.
This does not occur using pure standard c++.
I have narrowed down the cause to the use of IF.tellg() which simply gets the current stream position and should have no effect on the stream or file pointer.
If the line pos = IF.tellg(); (line 34) is removed, the problem goes away.
Could anyone verify this as being a bug for me or perhaps shed some light on what might be happening?
Thank you,
Chas
I think I may have stumbled across a bug, but I am not certain. This minimal program demonstrates what I am observing.
#include <QString>
#include <QMessageBox>
#include <QApplication>
#include <string>
#include <fstream>
using std::endl;
using std::string;
using std::ifstream;
using std::ofstream;
using std::streamsize;
int main (int argc, char* argv[])
{
QApplication app (argc, argv);
ofstream OF;
OF.open("testdata.txt");
for (int i = 1; i <= 10; ++i)
{
OF << "test line " << i << endl;
}
OF.close();
ifstream IF;
IF.open("testdata.txt");
string line;
streamsize pos;
while (IF.good())
{
getline (IF, line);
IF.peek();
pos = IF.tellg();
QMessageBox::information(0, "line", QString::fromStdString(line));
}
IF.close();
return 0;
}
Under Linux the code works as expected. i.e it saves 10 lines to a file then reads the file one line at a time printing the contents of each line in a message box.
..but under Windows, using the mingw compiler and qt library, the contents of the string are altered such that only offset portions of the string are being read and printed to the message box.
This does not occur using pure standard c++.
I have narrowed down the cause to the use of IF.tellg() which simply gets the current stream position and should have no effect on the stream or file pointer.
If the line pos = IF.tellg(); (line 34) is removed, the problem goes away.
Could anyone verify this as being a bug for me or perhaps shed some light on what might be happening?
Thank you,
Chas