[SOLVED] QMetaObject::connectSlotsByName not working for QDialog::accepted()
-
Hi everyone!
Before everything, thanks for reading.
I am developing an application using Qt (and Qt Creator). I use the Auto-connect feature and it works pretty well for many signals, but right now I have a problem with the signal accepted() of a QDialog.
I checked the QDialog's ObjectName (PropertyForm) and it's fine. I tried to make the slot "on_PropertyForm_accepted()" public, but it does not work.
Here is the related code fragment:
In "propertyform.h"
@namespace Ui {
class PropertyForm;
}class PropertyForm : public QDialog
{
Q_OBJECTpublic:
explicit PropertyForm(QWidget *parent = 0);
~PropertyForm();
void setPropertyValue(const QString& key, const QString& value);
QHash<QString, QString> getProperties() const;
void savePropertyValues();public slots:
void propertyAdded(const QString& name, const QString& key);
void propertyRemoved(const QString& key);
void clearAllValues();
void on_PropertyForm_accepted();private:
Ui::PropertyForm *ui;
QHash<QString, int> keyIndex;
QHash<QString, QString> properties;int findRowWithKey(const QString& key); void rebuildIndex();
};@
In "propertyform.cpp":
@void PropertyForm::on_PropertyForm_accepted()
{
savePropertyValues( );
}@It compiles without problems, but I get "QMetaObject::connectSlotsByName: No matching signal for on_PropertyForm_accepted()" in Application Output. Also, if it helps, I create three private variables of this class in my main window.
Any suggestions?
Thanks!
-
PropertyForm is your class. the autoconnect connects objects signals with your slots.
the logic is:
on_<sender name>_<signal name>
sender name is the name of the sender object, not a class name.
signal name is the name of the signal to connect.as you just want to do some special things during accept, overewrite "accept()":http://doc.qt.nokia.com/4.7/qdialog.html#accept virtual function. That's what it is for :-)
-
Hi and thanks for replying!
Yeah, it makes sense.. I followed your advice and overwrote accept() (in fact I think it is more efficent). Anyway, I would like to know if it is possible to use auto-connect feature for the current instance of the class, something like on_this_accepted(). I know you can achieve something like that outside the class (in the parent), but it wouldn't be good if you have to repeat the methods for each instance of the class. Maybe it can be done manually (using connect()), but not with auto-connect.
Also, Qt Creator generated that slot, so I think it is a bug, isn't it?
Thanks again and greetings!