[Qt-interest] Issues writing to QFile
Paul England
pengland at cmt-asia.com
Fri Mar 18 02:42:27 CET 2011
I've generally not had problems writing to streams before, but I've not
done them in this way before. I have a program which is getting data
on a socket. I want to write each line to a separate file (sort of).
The flow is generally something like:
get line -> store -> periodically parse any stored data -> process data
-> write data to file
Below is a rough transcription, as I have the source on an email-less
machine.
I'm not getting even the newlines in the QFile, in the write() routine.
So it's basically not writing to the QTextStream, or the QTextStream is
not writing it to the QFile. Before, I've always just opened the file,
opened the stream, and viola, it's worked. Is there an issue w/ keeping
it open? The "test" string I write when I first open the QFile is
always properly written, btw.
class my_dialog : public QDialog
{
Q_OBJECT
public:
my_dialog();
virtual ~my_dialog();
private:
QFile my_file;
QTextStream out_stream;
};
my_dialog::setup()
{
QFile file( "myfile.txt" );
if ( !file.open( QIODevice::WriteOnly ) ) {
// boo
} else {
out_stream.setDevice( &my_file );
out_stream << "test" << endl; // so far so good
}
}
my_dalog::parse()
{
// do whatever
QString str = socket_data_handler();
write( str );
}
my_dalog::write( const QString& str )
{
out_stream << str << endl;
if ( file.error() ) {
// error
} else if ( out_stream.device() == NULL ) {
// error
} else {
printf( "Success\n" );
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110318/3b4d6f90/attachment.html
More information about the Qt-interest-old
mailing list