Signals & Slots problems
-
I'm using the latest SDK on Fedora 13 64bit. I've been trying to follow the tutorials & examples provided to reaquaint myself with C++ & Qt. I'm having a problem trying to use the Signals & Slots in a small practice app. The slot I wrote to respond to a button click isn't listed in the Signals & Slots editor. I tried to connect as shown in the docs, but the compiler throws about a thousand errors. The docs don't say or show exactly where the connection should be (i.e. which file & where in the file). I've stomped over it so much that I have myself thoroughly confused. It doesn't help that I haven't tried to write anything in almost 8 years. Would anyone be willing to hold my hand for a bit & walk me through how to get this done? I know it can't be THAT hard. Thanks in advance for any help.
Ed
-
You can simply add connect() to your form constructor. Something like that:
@
MyForm::MyForm(QWidget *parent) : QWidget(parent)
{
//...
connect(ui->myButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
//...
}
@or create slot named as on_myButton_clicked() in form, containing myButton (replace it with your name for needed signal emitter).
-
two things I jsut want to remind u .
Make sure you write Q_OBJECT macro in you header fileand declare your slot in the slot section of the header :
@
class myForm ..
{
Q_OBJECTprivate slots:
void butonclick();}@
but when subclassing from a ui file , the last method of the abov reply is more conveniant as it auto-connect directly