qt 插槽和信号自动连接
qt slots and signalls autoconnecting
我正在使用 Qt 5.2.1。我读到 this, and that - it doesn't cover my case. I have QSqlTableModel , and a window that uses it. I want to react on its dataChanged 信号:
void QAbstractItemModel::dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles = QVector<int> ())
所以我在 windowClass 构造函数中初始化模型,如下所示:
kontrahentModel = new QSqlTableModel(this);
下面是插槽声明:
void on_kontrahentModel_dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles = QVector<int> ());
相同数量的参数 - 但它导致臭名昭着
QMetaObject::connectSlotsByName: No matching signal for (...)
我错过了什么?它只适用于 GUI 信号吗?
我在写这个问题时不小心修复了它...我的模型缺少名称。当我添加
kontrahentModel->setObjectName("kontrahentModel");
一切都很顺利...
但是 - "there is no rose without a thorn"。为模型分配父项时,一个老问题 returns - 此处描述:QSqlQueryModel with a parent - app crash
我正在使用 Qt 5.2.1。我读到 this, and that - it doesn't cover my case. I have QSqlTableModel , and a window that uses it. I want to react on its dataChanged 信号:
void QAbstractItemModel::dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles = QVector<int> ())
所以我在 windowClass 构造函数中初始化模型,如下所示:
kontrahentModel = new QSqlTableModel(this);
下面是插槽声明:
void on_kontrahentModel_dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles = QVector<int> ());
相同数量的参数 - 但它导致臭名昭着
QMetaObject::connectSlotsByName: No matching signal for (...)
我错过了什么?它只适用于 GUI 信号吗?
我在写这个问题时不小心修复了它...我的模型缺少名称。当我添加
kontrahentModel->setObjectName("kontrahentModel");
一切都很顺利...
但是 - "there is no rose without a thorn"。为模型分配父项时,一个老问题 returns - 此处描述:QSqlQueryModel with a parent - app crash