New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ROOT crash when parameter by value passed to slot: StrDup #7195
Comments
Please use
|
Thanks for the hint. I just tried that, now I do not get a crash, but rather a warning and the button name is not changed:
|
Well, this simple example works just fine for me on Windows and CentOS7:
|
Thanks for the nice example. It works on Ubuntu, too. Why is SetText() leading to a crash? Maybe we could add a short comment here in the documentation: "If you use a signal-slot connection with inline argument passed as (text) value, use ChangeText instead of SetText". |
Well, I'll check, but the signatures of |
Thanks for checking. My second use case was a combobox selection leading to a tgtextbutton change. I tried it with your example, but it is not working. Do you get a similar crash on Windows?
If I run it with the QtCreator debugger, it completely freezes the mouse, I have to open a terminal and call pkill qtcreator. (Which is something I rarely had needed to do before.) |
Yes. I will debug it |
This is what my debugger shows before it freezes: It looks as if the Selected(Int_t) signal argument (integer) is being passed as a string?. I was able to reproduce the crash isolatedly in a ROOT terminal:
If I select the first element of the Combo-Box, then cs = 0 and it does not crash because the if(cs) in the TString constructor. |
I didn't have time to look at it yet, but the integer is maybe the argument of the signal |
Yes, I just confirmed it by changing this: Now it does not crash, but instead of changing the text to the one I pass by value, it replaces it with the TGCombo text entry. |
I know that the signal/slot mechanism has some limitations, so that might well be one of them. |
Ok, thanks for the reply. Maybe a note in the documentation could be added specifying that it only works if the signal has the shape of Clicked() or Pressed(), not with extra arguments ?: https://root.cern.ch/root/htmldoc/guides/users-guide/WritingGUI.html#event-processing-signals-and-slots |
…slot with arguments by value Fixes root-project#7195
I provided a PR for this. Thanks for the excellent support. |
* fix typos * clarify slot args by value * emit signal with no arguments, for being able to safely connect with slot with arguments by value Fixes #7195 * rename to Changed for avoiding ambiguity/confusion * fix arg-by-value example
…oject#7228) * fix typos * clarify slot args by value * emit signal with no arguments, for being able to safely connect with slot with arguments by value Fixes root-project#7195 * rename to Changed for avoiding ambiguity/confusion * fix arg-by-value example
Describe the bug
According to https://root.cern.ch/root/htmldoc/guides/users-guide/WritingGUI.html#event-processing-signals-and-slots one can pass parameters by value to your slots.
Connect(myButton, "Pressed()","TH1",hist, "Draw(=\"LEGO\")");
For example, I was trying:
myTGCheckBox->Connect("Clicked()","TGTextButton", myButton, "SetText(=\"LEGOlegoemoryABCDEF\")");
But when I click on my checkbox, ROOT crashes then with:
If I try to pass other string combinations, then ROOT sometimes crash, sometimes not but puts weird characters or only part of the string in the TGTextButton.
Expected behavior
My TGTextButton would get the passed string correctly when the checkbox is clicked.
To Reproduce
Setup
The text was updated successfully, but these errors were encountered: