RE: TGTextView window close signal connect

From: Bertrand Bellenot <Bertrand.Bellenot_at_cern.ch>
Date: Thu, 29 Jul 2010 13:09:31 +0200


Hi Nicolas,  

Here is the proper way to do it:

void CloseWindow()
{

   printf("Quitting by user request\n");    gApplication->Terminate(0);
}

void nocrash()
{

   TGMainFrame *mf = new TGMainFrame (gClient->GetRoot(), 700, 200);    mf->SetCleanup(kDeepCleanup);
   TGTextView* cond = new TGTextView(mf);    mf->AddFrame(cond, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));

   mf->MapSubwindows();
   mf->MapWindow();
   mf->MoveResize(900, 600, 300, 300);

   cond->GetCanvas()->Connect("Destroyed()", NULL, NULL, "CloseWindow()");

   TCanvas* c1 = new TCanvas();
   c1->Connect("Closed()", NULL, NULL, "CloseWindow()"); }

i.e. you cannot (or must not) use new TGTextView(gClient->GetRoot()); you need a proper container (a TGCompositeFrame) gClient->GetRoot() returns a pointer on the root (desktop) window...

Cheers, Bertrand.

-----Original Message-----
From: Nicolas Produit [mailto:Nicolas.Produit_at_unige.ch] Sent: Thursday, July 29, 2010 08:48
To: Bertrand Bellenot
Cc: roottalk_at_root.cern.ch
Subject: Re: [ROOT] TGTextView window close signal connect

Hi,

here is the example:

crash.C:



void CloseWindow(){
  printf("Quitting by user request\n");
  gApplication->Terminate(0);
}

void crash(){
  TGTextView* cond=new TGTextView(gClient->GetRoot());

  cond->MapSubwindows();
  cond->MapWindow();
  cond->MoveResize(900,600,300,300);
  cond->GetCanvas()->Connect("Destroyed()",NULL,NULL,"CloseWindow()");
  TCanvas* c1=new TCanvas();
  c1->Connect("Closed()",NULL,NULL,"CloseWindow()"); }

session where the canvas was closed in clicking the window close on the c1 canvas. Everything is nice and smooth.

produit_at_produit-dell:~/bla$ root


ROOT 5.26/00 (trunk_at_31882, Dec 14 2009, 20:18:36 on linux)

CINT/ROOT C/C++ Interpreter version 5.17.00, Dec 21, 2008 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }.

root [0] .L crash.C
root [1] crash()
root [2] Quitting by user request

produit_at_produit-dell:~/bla$

session where the TGTextView was closed in clicking the window close on the TGTextView window. We get an error.

produit_at_produit-dell:~/bla$ root


ROOT 5.26/00 (trunk_at_31882, Dec 14 2009, 20:18:36 on linux)

CINT/ROOT C/C++ Interpreter version 5.17.00, Dec 21, 2008 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }.

root [0] .L crash.C
root [1] crash()
root [2] Error in <RootX11IOErrorHandler>: fatal X11 error (connection
to server lost?!)

root [2] .q
produit_at_produit-dell:~/bla$

On Wed, 2010-07-28 at 19:12 +0200, Bertrand Bellenot wrote:

> Hi Nicolas,
> 
> You have to be careful when using signals slots with objects being 
> destroyed, since the actual X window may already be gone and the slot 
> still trying to access it...
> Anyway, it is hard to tell exactly what's going on with so little 
> information. Could you provide a short running macro reproducing the 
> problem?
> 
> Cheers, Bertrand.
> 
> On 7/28/2010 5:59 PM, Nicolas Produit wrote:
> > Hi,
> >
> > is it possible to Connect to a window close event of an object of
type
> > TGTextView?
> >
> > I tried:
> >
> > cond=new TGTextView(gClient->GetRoot());
> > cond->MapSubwindows();
> > cond->MapWindow();
> > cond->MoveResize(900,600,300,300);
> >

cond->GetCanvas()->Connect("Destroyed()","MonitorFrame",this,"CloseWindo w()");
> >
> > this does not give error messages so it seems the Destroyed() signal
> > from the TQObject can be connected but then when killing the window
I
> > get a:
> > Error in<RootX11IOErrorHandler>: fatal X11 error (connection to server
> > lost?!)
> > rather to a call to my subroutine (the subroutine work for connected
> > TCanvas on signal Closed())
> >
> > Thanks
> >
> >    
> 

-- 
Nicolas Produit
ISDC, Data Centre for Astrophysics   Phone:+41 22 379 2140
16, Chemin d'Ecogia                  Fax:  +41 22 379 2133
CH-1290 Versoix                      www:  http://isdc.unige.ch/~produit
Received on Thu Jul 29 2010 - 13:09:37 CEST

This archive was generated by hypermail 2.2.0 : Fri Jul 30 2010 - 17:50:01 CEST