ich habe ein Problem mit dem SQL-Modul, soweit läuft alles super, aber die Klasse QSqlRelationalDelegate macht Probleme. Selbst folgender Code:
Code: Alles auswählen
QSqlRelationalDelegate delegate(NULL);aus.g++ (GCC) 4.1.2 hat geschrieben:Fehler: »QSqlRelationalDelegate« wurde in diesem Gültigkeitsbereich nicht definiert
Eingebundene Header sind:
Code: Alles auswählen
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlRelationalTableModel>
#include <QtSql/QSqlRelationalDelegate>Ich verwende Qt in der OpenSource-Linux-Variante Version 4.3.3. Es ist möglich, aber unwahrscheinlich, dass mein Build Schrott ist. Ich habe Qt4 nativ aus den Fedora-Repositories installiert, auch schon den Source von der Trolltech-Seite gezogen und kompiliert, aber funktioniert hat es dennoch nicht.
Falls es jemanden interessiert, so schaut meine "qsqlrelationaldelegate.h" (im QtSql-Verzeichnis, die Version im Qt-Verzeichnis ist aber identisch) aus:
Code: Alles auswählen
#ifndef QSQLRELATIONALDELEGATE_H
#define QSQLRELATIONALDELEGATE_H
#ifdef QT_GUI_LIB
#include <QtGui/qitemdelegate.h>
#include <QtGui/qlistview.h>
#include <QtGui/qcombobox.h>
#include <QtSql/qsqlrelationaltablemodel.h>
QT_BEGIN_HEADER
QT_MODULE(Sql)
class QSqlRelationalDelegate: public QItemDelegate
{
public:
explicit QSqlRelationalDelegate(QObject *parent = 0)
: QItemDelegate(parent)
{}
~QSqlRelationalDelegate()
{}
QWidget *createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
const QSqlRelationalTableModel *sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
if (!childModel)
return QItemDelegate::createEditor(parent, option, index);
QComboBox *combo = new QComboBox(parent);
combo->setModel(childModel);
combo->setModelColumn(childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn()));
combo->installEventFilter(const_cast<QSqlRelationalDelegate *>(this));
return combo;
}
void setEditorData(QWidget *editor, const QModelIndex &index) const
{
const QSqlRelationalTableModel *sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
QComboBox *combo = qobject_cast<QComboBox *>(editor);
if (!sqlModel || !combo) {
QItemDelegate::setEditorData(editor, index);
return;
}
combo->setCurrentIndex(combo->findText(sqlModel->data(index).toString()));
}
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (!index.isValid())
return;
QSqlRelationalTableModel *sqlModel = qobject_cast<QSqlRelationalTableModel *>(model);
QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
QComboBox *combo = qobject_cast<QComboBox *>(editor);
if (!sqlModel || !childModel || !combo) {
QItemDelegate::setModelData(editor, model, index);
return;
}
int currentItem = combo->currentIndex();
int childColIndex = childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn());
int childEditIndex = childModel->fieldIndex(sqlModel->relation(index.column()).indexColumn());
sqlModel->setData(index,
childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole),
Qt::DisplayRole);
sqlModel->setData(index,
childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole),
Qt::EditRole);
}
};
QT_END_HEADER
#endif // QT_GUI_LIB
#endif // QSQLRELATIONALDELEGATE_HGoogle und Forensuche hab ich natürlich benutzt, Google liefert nichts Brauchbares und die Forensuche liefert nur 4 oder 5 Threads zum Stichwort "QSqlRelationalDelegate", die allesamt nichts mit dem Problem zutun haben.
Vielen Dank für eventuelle Hilfe im Voraus, ich hoffe ich habe keine wichtigen Infos vergessen!