Object::connect: No such slot MainWindow::currentChanged() in mainwindow.cpp:163Object::connect: (receiver name: 'MainWindowClass')QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
model1->setEditStrategy(QSqlTableModel::OnRowChange);
class Calendar : public QItemDelegate { Q_OBJECT public: Calendar(bool calpopup = true, QObject *parent = 0); QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index); void setEditorData(QWidget *editor, const QModelIndex &index); void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index); void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index); private: bool m_calpopup; };
C++ (Qt)ImageDelegate::ImageDelegate(QObject *parent) : QItemDelegate(parent) { } QWidget *ImageDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex &index) const { QComboBox *comboBox = new QComboBox(parent); if (index.column() == 6) { comboBox->addItem(tr("Да")); comboBox->addItem(tr("Нет")); } connect(comboBox, SIGNAL(activated(int)), this, SLOT(emitCommitData())); return comboBox; } void ImageDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QComboBox *comboBox = qobject_cast<QComboBox *>(editor); if (!comboBox) return; int pos = comboBox->findText(index.model()->data(index).toString(), Qt::MatchExactly); comboBox->setCurrentIndex(pos); } void ImageDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QComboBox *comboBox = qobject_cast<QComboBox *>(editor); if (!comboBox) return; model->setData(index, comboBox->currentText()); } void ImageDelegate::emitCommitData() { emit commitData(qobject_cast<QWidget *>(sender())); }