PDA

View Full Version : QPushButton click



qutron
29th November 2010, 14:36
Hi, there.
I got little problem:
i connected QPushButton clicked() signal to my custom slot:


QObject::connect( ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));
but when I click on pushButton signal clicked() is sent twice ( on_pushButton_clicked() is called twice).
Any ideas?

Zlatomir
29th November 2010, 14:39
The slot is connected twice.
Once by auto-connect (because of the name on_OBJECTNAME_SIGNALNAME), and once by you (when you call connect)

LE: I couldn't find the reference for auto connect, only this (http://doc.qt.nokia.com/4.0/designer-using-a-component.html#a-dialog-with-auto-connect) (but there isn't much to say anyway)
To solve your issue, use a different name and QObject::connect(...), or use the name-ing convention and the signal will be auto-connected with the slot (remember two connections between one signal and one slot means two executions of the slot for each time the signal is emitted)

qutron
29th November 2010, 14:47
OH, I got it. Thanks!!