[gtkmm] Re: Why would c style file IO work and not c++ style?



If no one answers me, I'll answer myself!  :)

I updated gtkmm, libsigc++, compiled all of that with g++ 3.2,
recompiled this with 3.2 adn those updates and now it works either way. 
So it was either a bug in:
gtkmm-2.0.0
libsigc++-1.2
g++-2.96

Mark

On Mon, 2002-12-16 at 20:51, Mark Jones wrote:
> Ok, this has me very puzzled, if I change that file IO over to c style
> IO, it works fine in either place (called from the menu item signal
> handler or the dialog's button's signal handler).
> 
> Why would this matter?  The C++ IO code is just fine as far as I can
> see, it works from the dialog, it works from the console/command line
> test progrram I wrote, and I see nothing wrong with it.  The C code is
> completely the same as it, just different IO functions.
> 
> Is this a bug in gtk or gtkmm?  I was starting to think it must have to
> do with what thread was calling it (since it worked from the dialog and
> not the main window, when the calling line was exactly the same, and I
> assume there are multiple threads inside gtk/gtkmm).  Now that c style
> IO works, I don't suspect a thread so much anymore...I don't know what
> to suspect.
> 
> Mark
> 
> Modified code shown below, if you want to run it, comment one section or
> the other out completely.  Currently the c++ style IO is commented out.
> 
> bool saveFile( const std::string fileName, 
>                const std::string textToWrite )
> {
> 
> /*=-=-=-=-
>     // This causes a hang if called from a menu item signal handler
> -------
>     //
> --------------------------------------------------------------------
>     ofstream outFile;
>     outFile.open( fileName.c_str(), ios::out|ios::binary );
>     if( outFile.bad() )
>     {
>         cerr << "Unable to open " << fileName << endl;
>         return false;
>     }
> 
>     cout << "Writing out: " << fileName << endl;
> 
>     outFile.write( textToWrite.c_str(), textToWrite.length() );
> 
>     cout << fileName << " writen out!" << endl;
>     
>     outFile.close();
> =-=-=-=-*/
> 
>     // This does not causes a hang if called from a menu item signal
> handler
>     //
> --------------------------------------------------------------------
> 
>     FILE *outFile;
> 
>     if( ( ( outFile = fopen( fileName.c_str(), "wb" ) ) == NULL ) )
>     {
>         cerr << "Unable to open " << fileName << endl;
>         return false;
>     }
> 
>     cout << "Writing out: " << fileName << endl;
> 
>     fwrite( textToWrite.c_str(), textToWrite.length(), 1, outFile );
> 
>     cout << fileName << " writen out!" << endl;
> 
>     fclose( outFile );    
> 
>     return true;
> }
> 
> 
> 
> 
> On Mon, 2002-12-16 at 14:08, Mark Jones wrote:
> > I have created a very short and simple demonstration of the problem.  I
> > have attached it to this e-mail.
> > 
> > To see this work after reviwing it, compiling it and starting it:
> > 
> > 1st
> > 
> > view->preferences
> > save
> > note output in console window where you started the program from
> > in another window, view contents of "test" which is the file it creates
> > AND DEFINITELY RUN THIS IN ITS OWN DIRECTORY SO YOU DON'T CLOBBER A FILE
> > NAMED TEST IN YOUR DIRECTORY  :)
> > 
> > 2nd
> > file->save
> > note hang, note output in console window (compare to myFileWriter.cc to
> > see where it hangs)
> > in another window, view contents of "test" which is the file it creates
> > 
> > 3rd
> > restart it
> > file->save
> > note hang
> > in another window, view contents of "test" which is the file it creates
> > 
> > Note the text area is just there in both the main window and dialog, it
> > doesn't actually do anything with it, even during the save.
> > 
> > Can anyone see what is wrong?
> > 
> > Mark
> > 
> > On Mon, 2002-12-16 at 01:55, Mark Jones wrote:
> > > I have run into something very strange.  I have a file writer, and I can
> > > use that file writer to write to a file when I call it from the signal
> > > handler for a button that is on my own dialog (and the dialog is brought
> > > up by a signal handler for a menu item in my application).  However, if
> > > I try to do the same thing from the signal handler from my File->Save
> > > menu item, it hangs the application (it is freezing on the first
> > > ofstream::write() call).  Is there something special I need to do to
> > > write to files from different places in a gtkmm program?
> > > 
> > > The file writer is fine I think because it works when called from the
> > > dialog and in a command line driver program I wrote to test it.
> > > 
> > > Any ideas of what is going on?
> > > 
> > > Thanks!
> > > 
> > > Mark
-- 
Mark Jones <mark jones106 verizon net>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]