Hi, I'm a 10+ year C++ programmer but n3wb to Qt...

I've successfully installed the Qt 4.5.2 SDK (MinGW g++) but, since I primarily use VC++, also installed the VS2008 plugin and built the Qt 4.5.2 sources for VC++ in a separate directory. After fixing some Environmental Values/Paths issues between the 2 Qt now works fine under both compilers/IDEs.

I've made some simple test programs to try out Qt, but noticed that my custom slots always gets called twice for a single signal - and it happens in both IDEs

In QtDesigner I add a signal/slot to a QPushButton where the Sender is the QPushButton (signal is clicked()) and the Receiver a custom slot (called on_pbAdd_clicked()) on my form class derived form QDialog.

Since QtDesigner does not automatically generate the slots anymore, I've declared the slots like this:

Qt Code:
  1. class Dialog : public QDialog
  2. {
  3. Q_OBJECT
  4. public:
  5. Dialog(QWidget *parent = 0, Qt::WFlags flags = 0);
  6. ~Dialog();
  7. private:
  8. Ui::DialogClass ui;
  9. public slots:
  10. virtual void on_pbAdd_clicked(void);
  11. virtual void on_pbRemove_clicked(void);
  12. };
To copy to clipboard, switch view to plain text mode 

The slot is implemented like this:

Qt Code:
  1. void Dialog::on_pbAdd_clicked(void)
  2. {
  3. if(ui.leEdit->text().length() > 0) {
  4. ...
  5. }
  6. }
To copy to clipboard, switch view to plain text mode 

I've tried to debug the issue: When the button is clicked one of the void QMetaObject::activate(...) functions in qobject.cpp gets called, specifically:

Qt Code:
  1. void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv)
  2. {
  3. ....
  4. int count = connectionLists->at(signal).count();
  5. for (int i = 0; i < count; ++i) {
  6. const QObjectPrivate::Connection *c = &connectionLists->at(signal)[i];
  7. ...
  8. receiver->qt_metacall(QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv);
  9. ...
  10. }
  11. ...
  12. }
To copy to clipboard, switch view to plain text mode 

The count variable is set to 2 from the call to connectionLists->at(signal).count();. This means the next for loopis executed twice - which causes the slot to be called twice in the receiver->qt_metacall() function call. This resolves to a call to Dialog::qt_metacall(...) that was generated by the moc, which looks like this:

Qt Code:
  1. int Dialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
  2. {
  3. _id = QDialog::qt_metacall(_c, _id, _a);
  4. if (_id < 0)
  5. return _id;
  6. if (_c == QMetaObject::InvokeMetaMethod) {
  7. switch (_id) {
  8. case 0: on_pbAdd_clicked(); break;
  9. case 1: on_pbRemove_clicked(); break;
  10. default: ;
  11. }
  12. _id -= 2;
  13. }
  14. return _id;
  15. }
To copy to clipboard, switch view to plain text mode 

The case 0 in the switch statement then calls my on_pbAdd_clicked() slot - which seems perfect. So everything seems to work fine, with the exception of that connectionLists->at(signal).count(); value that is returned, which result in the slot being called twice!

I am not yet familiar with the Qt code-base, so can anybody maybe help and maybe shed some light on this? How does one overcome this?

Thanx