PDA

View Full Version : qt 4.3.4: bind "connect" slot action at runtime



paule22
23rd August 2008, 18:27
Hello,

how can I connect


connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));

at runtime (closeAllWindows) ?

thanks for helping

Jens




QObject::connect(
kawin[win]->btn[kawin[win]->PushButtonCount-1], // the button
SIGNAL(clicked()), // the signal
kawin[win], // the window/widget
SIGNAL(kawin[win]->btn[kawin[win]->PushButtonCount-1]->buttonClicked())
);

jacek
23rd August 2008, 22:09
how can I connect

connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));

at runtime (closeAllWindows) ?
All connections are established at the runtime.


QObject::connect(
kawin[win]->btn[kawin[win]->PushButtonCount-1], // the button
SIGNAL(clicked()), // the signal
kawin[win], // the window/widget
SIGNAL(kawin[win]->btn[kawin[win]->PushButtonCount-1]->buttonClicked())
);
You have to pass a string literal to SIGNAL() and SLOT() macros. If you want to determine what to connect to at runtime, you can't use these macros. Luckily they have very simple definitions:

#define SLOT(a) "1"#a
#define SIGNAL(a) "2"#a

But do you really don't know the name of the destination slot/signal a priori?


Also take a look at QSignalMapper and QButtonGroup classes.