TClassMenuItem not connected to function


I’m currently porting a software from root5 to root6. I’m experiencing an issue where the menuitem are not triggering the functions they are supposed to. I’m using the root API from a C++ compiled application. Menu items are declared like this in the C++ code:

 laxmenu->AddFirst(new TClassMenuItem(
       TClassMenuItem::kPopupUserFunction,claxis,"Zoom ALL X as last","URZoomAllXAsLast",0,"TObject*",0,0));

The function is declared in a header file:

void URZoomAllXAsLast(TObject* objaxis);

The dictionary is generated using this linkdef file:

#pragma link C++ function URZoomAllXAsLast;

Using root, I’m able to call the function:

root [0] gSystem->Load("")
(int) 0
root [1] URZoomAllXAsLast(0)

 *** Break *** segmentation violation

(Segmentation fault is expected, the function does not check for NULL argument).

But in the application, a click on the corresponding menu item does not call the function. Any idea why the function is not connected to the click event ?


Welcome to the ROOT forum

As it looks like a GUI (TClassMenuItem) (?) question I guess @bellenot might help you.

Please provide a complete example we can try. And BTW, does the ${ROOTSYS}/tutorials/gui/customContextMenu.C work for you?

So I just added these lines in ${ROOTSYS}/tutorials/gui/customContextMenu.C

   n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                          "Zoom ALL X as last","URZoomAllXAsLast",0,"TObject*",2);

with URZoomAllXAsLast being:

void URZoomAllXAsLast(TObject* objaxis)
   printf("URZoomAllXAsLast %tx\n",(intptr_t)objaxis);

And it works just fine:

C:\root-dev\build\x64\debug\tutorials\gui>root -l customContextMenu.C
root [0]
Processing customContextMenu.C...
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [1] URZoomAllXAsLast 1ba8ab55d40

Thanks. I will try to come up with a simple project exhibiting the issue.

Regarding your answer, please note my issue happens in a compiled application, not a script launched using root.

Here is a simple example, using customContextMenu.c as a starting point: https:/ / (Broken URL, new users are not allowed to post links :frowning: )

Callbacks are not called in the compiled application, but it works when the menus are built from the root interpreter.

OK, thanks. It will take a bit of time, I work on Windows and obviously (whatever it is) will not work. I’ll keep you informed

OK, I can reproduce the issue. Investigating…

It looks like an interpreter issue. If I declare it this way:

   gInterpreter->Declare("void URZoomAllXAsLast(TObject* objaxis) { printf(\"URZoomAllXAsLast %zx\\n\",(intptr_t)objaxis);}");

It works… So I’ll have to dig into the interpreter, unless @pcanal or @Danilo has an idea…


I played a bit with my test app. It looks like a simple include statement in gInterpreter->Declare is enough:

Now all the callbacks are correctly called on a menu click.


OK, thanks for the info, I’ll check

Another thing I have tried, that may give a hint about the interpreter issue, is a proxy function:

But this test failed with the following error after a click on the menu item:

IncrementalExecutor::executeFunction: symbol '_Z16URZoomAllXAsLastP7TObject' unresolved while linking [cling interface function]!
You are probably missing the definition of URZoomAllXAsLast(TObject*)
Maybe you need to load the corresponding shared library?

Well, in CMake, one needs

set_target_properties(libCallbacks PROPERTIES ENABLE_EXPORTS 1)

but with your system, I can’t tell

In the proxy test, URZoomAllXAsLast was not found due to name mangling being disabled by extern "C". The proxy workaround also works if I reenable C++ name mangling in callbacks.h.


I’m not sure to understand, is this supposed to fix the issue about functions not found by the interpreter, or it is a comment about ?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.