PDA

View Full Version : Connecting signal and slot by name



grayfox
22nd July 2011, 08:38
I am currently using this code to connect them by name and it actually works, is this the supported way of doing so?



int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton b;
b.show();

// connect
b.connect(&b, "2clicked()", &app, "1quit()");

// disconnect
b.disconnect(&app, "1quit()");

return app.exec();
}


The reason I am doing this is because I want to be able to save/load actions using xml file.

MarekR22
22nd July 2011, 09:00
SIGNAL and SLOT are macros which convert argument to string with prefix, so you just resolved those macros. It is recommended to use macros (easy to read and ease to maintain code, for example in Qt Creator code completion or renaming of method will work only with macro).