[Qt-interest] Issues writing to QFile
sarvesh saran
aquarian.thunder at gmail.com
Fri Mar 18 05:29:17 CET 2011
Hi,
You may want to look at my_dialog::setup() again....file will go out of
scope at the end of setup().
But then again, this could be a typo as this is a rough transcription.....
Also, in QString
str = socket_data_handler(); check the value of str and see that it is not
empty (unlikely)...
thanks,
Sarvesh
On Fri, Mar 18, 2011 at 7:12 AM, Paul England <pengland at cmt-asia.com> wrote:
> 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" );
> }
> }
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110318/e27f8457/attachment.html
More information about the Qt-interest-old
mailing list