1

I have a problem with slots and signals. I created buttons and connected them to the clicked() slot. Then i decided to connect signals and slots manually and since then when I click the button it calls its function twice.

connect(ui->okButton, SIGNAL(clicked()), this, SLOT(on_okButton_clicked()));

void settingswindow::on_okButton_clicked()
{
    qDebug() << "ok clicked";
    this->close();
}

I was looking for the answer on google, but all i found was this: Where is the generated code of qt signals slots editor but my *.ui file looks like this: pastebin to the code. As you can see there's only one line with and nothing more. I can't find where the information about signals and slots is saved. Rebuild and clean options won't help.

4
  • Looks like a bug of Qt. Try to delete this button and add it again (maybe changing the name of it) Commented Dec 22, 2015 at 12:43
  • 1
    i don't know what to say... I've been struggling for like 2 hours with this problem and i didn't try the simplest solution. To delete the button and add it again with the same name.. Thank you duDE!
    – siwers
    Commented Dec 22, 2015 at 12:49
  • 1
    This is not a bug. Look, read this... doc.qt.io/qt-5/…
    – Devopia
    Commented Dec 22, 2015 at 13:07
  • Well, this explains a lot, because i was using that on_objectName_signalName pattern. Thanks
    – siwers
    Commented Dec 22, 2015 at 13:28

1 Answer 1

3

This is not a bug in Qt. If you look at the generated code for your ui_*.h file, you'll notice that the last statement executed in the setupUi() function is a call to QMetaObject::connectSlotsByName().

Since your slot already conforms to the naming convention that this function is looking for, your slot is automatically connected to the signal.

By manually connecting the signal to the slot, in your settingswindow class, you effectively duplicate the connection.

As @Devopia mentioned, this is a documented feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.