GUI: slot problem

Dear all,
I have a trivial GUI application I compile with c++. There’s a button and whenever pressed it should print a “Hello” string. The compilation is perfectly ok. The interpreter does execute correctly.
However, in the compiled version I get an error message after the GUI is displayed (correctly):
Error in TQObject::CheckConnectArgs: slot run_me() does not exist
Here my code:

int main()
//void gui()
{
  TApplication *theApp = new TApplication("tgupdate", 0,0);
  TGMainFrame *main_frame = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);

  TGTextButton *prout = new TGTextButton(main_frame,"Do Something");
  prout->Connect("Pressed()", "tgupdate", 0, "run_me()");
  main_frame->AddFrame(prout, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
  prout->MoveResize(10,10,70,24);

  main_frame->MapSubwindows();
  main_frame->MapWindow();
  main_frame->Resize(100,50);

  theApp->Run();
}

class tgupdate : public TGMainFrame {
private:
  TApplication *theApp;
  TGMainFrame *main_frame;
  TGTextButton *prout;
public:
  tgupdate();
  virtual ~tgupdate();  
  void run_me();
  ClassDef(tgupdate, 1)
};

void tgupdate::run_me()
  {
  cout << "Hello!\n";
  }

The compilation is done with the following Makefile:

CC      = /usr/bin/g++
CFLAGS  = -g -O2
INCLUDES = -I$(ROOTSYS)/include
LDFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags --glibs)
EXE = GUI
SRC = gui.C
DICT = gui.cxx

$(EXE): $(DICT)
        $(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDES) -o $(EXE) $(DICT)

$(DICT): $(SRC)
        rootcint -f $(DICT) -c $(SRC) LinkDef.h

What am I doing wrong? Unfortunately the tutorials are all (?) examples of interpreter codes.

Thanks in advance
Giovanni

Hi Giovanni,

If you try to connect the “Pressed()” signal to the “run_me()” slot of the “tgupdate” class, then you have to give the pointer to an instance of you class as third argument, and not zero. Something like this:

[...] tgupdate *main_frame = new tgupdate(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame); prout->Connect("Pressed()", "tgupdate", main_frame, "run_me()"); [...]
(assuming you properly implement/instanciate your tgupdate class). Or if you prefer to use a function in the global scope, try to use this way:

[...] prout->Connect("Pressed()", 0, 0, "run_me()"); [...] // with runme defined like this: void run_me() { cout << "Hello!\n"; }
And as said previously, there are many example showing how to use signal/slots, and even in stand-alone application (see for example $ROOTSYS/test/guitest.cxx)

Cheers, Bertrand.

Hi,
I did remove my “tgupdate” class, leaving simply as you suggest

  TGTextButton *prout = new TGTextButton(main_frame,"Do Something");
  prout->Connect("Pressed()", 0, 0, "run_me()");

and

void run_me() { cout << "Hello!\n"; }

but the problem is still there:
Error in TQObject::CheckConnectArgs: slot run_me() does not exist
It must be something more macroscopic.

Hi Giovanni,

Take a look at the attached code, it uses both slots (global function and class method). Hope this will help you to understand. Note also the modification in LinkDef.h and in the Makefile (renamed Makefile.txt to allow uploading)

Cheers, Bertrand.
Makefile.txt (950 Bytes)
tgupdate.cxx (1.07 KB)
tgupdate.h (246 Bytes)
LinkDef.h (186 Bytes)

Thank you Bertrand!
That’s exactly what I was looking for, a trivial example that works. I’d include something like that in the ROOT tutorials, but that’s my personal taste. guitest.cxx contains a lot more, and so does the general Makefile.

Giovanni