TClassMenuItem not connected to function

Hi,

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("libdy_c.so")
(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 ?

Emmanuel.

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);
   l->AddFirst(n);

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:/ /github.com/EmmanuelP/root-test (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 meson.build (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…

Hi,

I played a bit with my test app. It looks like a simple include statement in gInterpreter->Declare is enough: https://github.com/EmmanuelP/root-test/commit/c8d33613108d9e5e41760a63434796dae08a23b6.

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

Emmanuel.

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: https://github.com/EmmanuelP/root-test/commit/f66078f85ef0a2fb731bb9a5f5c0df21136e5bbd

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.

https://github.com/EmmanuelP/root-test/commit/1c3380f8827a335799fc87d253715fec0b8f74e3

Hi,

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 https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/12?u=emmanuel ?

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