qt插槽和信号自动连接

时间:2015-01-15 20:49:42

标签: qt qt5 signals-slots qt5.2

我正在使用Qt 5.2.1。我看过thisthat - 它并不能涵盖我的案例。我有QSqlTableModel,以及一个使用它的窗口。我想对其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:(...)

没有匹配的信号

我错过了什么?它只适用于GUI信号吗?

1 个答案:

答案 0 :(得分:2)

我在写这个问题的时候意外修理了......我的模特错过了一个名字。当我添加

kontrahentModel->setObjectName("kontrahentModel");

所有人都像魅力......

但是 - “没有刺就没有玫瑰”。为模型分配父项时,会返回旧问题 - 此处描述:QSqlQueryModel with a parent - app crash