RE: connecting signals & slots

From: Fine, Valeri <fine_at_bnl.gov>
Date: Thu, 25 Jan 2007 17:40:12 -0500


Hi Rogger,

I think you need something like this
( Let me know whether I should elaborate further )

class MyFitButton : public TGTextButton {   private:

     TGraph *fGraph;
     TF1 *fF1;

  public:
   MyFitButton( <repeat here TGButton class signature> )

           : TGTextButton (  . . .  )
          , fGraph(0), fF1(0) {}

   void SetGraph(TGraph *g) { fGraph = g;}    void SetFun1(TF1 *f) { fF1 = f;}

   TGraph *Graph() const {return fGraph;}    TF1 *Fun1() const { return fF1;}
};

class MyMainFrame {
 private:
   MyFitButton *fFitButton;
...
public:
  void Fit(TGraph*, TF1*);
...
}

MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) { ...

   fFitButton = new MyFitButton(fHframe2, "&Fit");

   fFitButton->SetGraph(myGraph);
   fFitButton->SetGraph(myFun1);
   fFitButton->Connect("Clicked()","MyMainFrame",this,"Fit()");
   fHframe2->AddFrame(fit, fLbutton);
...
}

void MyMainFrame::Fit()
{

 // Since you use the TGraph object *name*
 // you do not need any retrieving of TF1 object.
 // The proper object is to be found by name with Fit method alone
 //  TF1 all = *fFitButton->Fun1();

  TGraph *graph = fFitButton->Graph();
  graph->Fit("all");
}

Best Regards

                         Valeri Fine


Brookhaven National Laboratory
Upton, NY 11973, USA
Phone: +1 631 344 7806
Fax: +1 631 344 4206
E-mail: fine_at_bnl.gov
> -----Original Message-----
> From: Roger Mason [mailto:rmason_at_esd.mun.ca]
> Sent: Thursday, January 25, 2007 4:20 PM
> To: Fine, Valeri
> Cc: roottalk_at_pcroot.cern.ch
> Subject: Re: [ROOT] connecting signals & slots
> 
> Hi Valeri,
> 
> "Fine, Valeri" <fine_at_bnl.gov> writes:
> 
> > That has a few states like "pressed" "clicked" etc, all of those can
be
> > reported via Signal / Slot mechanism.
> 
> It is the "Clicked" state for which I need a response.
> 
> > I would like to call your attention the only thing *you* want to
know
> > from the button object is how the user has interacted with this button.
> 
> > The user can do only TWO things with the GUI component like button.
> > He/she either press it or release it. That's all and this *is*
signaled.
> > It is up to your code how to respond. At this point your code can *pull*
> > all information it needs. There is no need to pass all parameters
> > through the signal / slot.
> 
> OK, that parameter passing is what I have been trying to do.
> 
> > The only thing you should pass via this
> > channel is the flag that is to notify you about the user intention
and
> > whether the information is ready to be fetched.
> 
> So, I need to define a (global?) flag and, when (in this case) the
> starting parameters for my fit are entered, set it to "True" then test
> for "True" in the slot?
> 
> >  Yes, the code should "know" where the information should be
> > "phishing". Have you problem with the "phishing"?
> 
> Yes.
> 
> >  Do you want to
> > pass the object pointer?
> 
> Well, I need some way for the TF1 and the TGraph to which it is to be
> fitted to be dispatched to the slot (I think).
> 
> > You can send such pointer from the signal
> > to the slot too. The later is simple and it should be sufficient.
> >
> 
> Well, that is what have been trying to do:
> 
> class MyMainFrame {
> ...
> public:
>   void Fit(TGraph*, TF1*);
> ...
> }
> 
> MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) {
> ...
>    fit = new TGTextButton(fHframe2, "&Fit");
>    fit->Connect("Clicked()","MyMainFrame",this,"Fit(TGraph&, TF1&)");
>    fHframe2->AddFrame(fit, fLbutton);
> ...
> }
> 
> void MyMainFrame::Fit(TGraph *graph, TF1 *thefit){
>   TF1 all = *thefit;
>   graph->Fit("all");
> }
> 
> When I compile, with ACLiC, compilation works but this error results:
> 
> Error in <TQObject::CheckConnectArgs>: slot
> MyMainFrame::Fit(TGraph&,TF1&) does not exist
> 
> I assume this is because the signature for Fit() does'nt correspond to
> that in the Connect() method.  The present bodge is just one of
> several I have tried.
> 
> Thanks for your help.
> 
> Roger
Received on Thu Jan 25 2007 - 23:40:35 CET

This archive was generated by hypermail 2.2.0 : Fri Jan 26 2007 - 23:50:00 CET