The connectable signals of a widget are currently listed under "Public Attributes" in the documentation. E.g. for MessageBox: https://tgui.eu/documentation/0.8/classtgui_1_1MessageBox.html#pub-attribs
(I am aware that you might not search them there and that you have to know where to look before you can find them)
MessageBox has a "ButtonPressed" signal which has the text of the pressed button as optional parameter, so you would have something like this:
messageBox->connect("ButtonPressed", [&retVal](const std::string& button){
if (button == "OK")
retVal = 0;
else if (button == "Cancel")
retVal = 1;
});