GTK-- How do I add some text to a Gtk_Text ?



Hi,

This is an easy one for you; for me it isn't :(.

I'm trying to write something in my Gtk_Text and the result is that the
Gtk_Text appear as an separate window !?! What's funny is that this
window rescales itself when the container that keeps it rescales, even
that they are separate windows (the place in the container, a HBox,
where the text box should be is empty). If I close the window that keeps
the Gtk_Text, I get this:

** ERROR **: an x io error occurred
make: *** [run] Aborted

or

** ERROR **: sigint caught

I've attached a simple code that produces this.
The code try to read the file ".modelrc" and show it in the Gtk_Text.

TIA,

Ionutz
#include <gtk--/widget.h>
#include <gtk--/window.h>
#include <gtk--/main.h>
#include <gtk--sig.h>
#include <gtk--/box.h>
#include <gtk--/text.h>
#include <gtk--/scrollbar.h>
#include <gtk--/adjustment.h>
#include <fstream>
#include <sys/stat.h> 
#include <unistd.h> 

class Modeling : public Gtk_Window {
public:
  Gtk_Adjustment adj;
  Gtk_HBox ihbox;
  Gtk_Text itext;
  Gtk_VScrollbar iscrollbar;
  gchar *rcBuffText;
  gchar rcFileName[32];

  Modeling() : 
    adj(0,0,100), 
    itext(0,&adj), 
    iscrollbar(&adj) 
    {
      add(&ihbox);
      ihbox.pack_start(&itext,false);
      itext.set_usize(400,300);
      itext.set_editable(true);
      ihbox.pack_start(&iscrollbar,false);
      iscrollbar.show();
      itext.show();
      ihbox.show();
      // show the .modelrc in the rcText widget
      sprintf(rcFileName, ".modelrc");
      ifstream rcin;
      struct stat rcstat;
      stat( rcFileName, &rcstat);
      rcin.open(rcFileName, ios::in);
      if( rcin ){
	rcBuffText = new gchar[rcstat.st_size];
	rcin.read(rcBuffText, rcstat.st_size);
	itext.insert(0,0,0, rcBuffText, -1);
	rcin.close();
      }
    }
};

int main( int argc, char **argv )
{
  Gtk_Main app( &argc, &argv ); // (7)
  Modeling mainWindow; // (6)
  
  mainWindow.show(); // (4)
  
  app.run(); // (8)
  return 0;
}



1
2
3
4
5
6
7
8
9
10
a
aa
aaa
aaaa
aa aa qq
xcz




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