Lets assume for simplicity that the controller creates and owns the model (but you can make it setable with a bit of more effort)
{
Q_OBJECT
public:
explicit Controller
(QObject *parent
= 0);
public slots:
void updateModel();
private:
private slots:
};
class Controller : public QObject
{
Q_OBJECT
public:
explicit Controller(QObject *parent = 0);
QSqlQueryModel *model() const { return m_model; }
void setView(QTableView *view);
public slots:
void updateModel();
private:
QSqlQueryModel *m_model;
private slots:
void onCellClicked(const QModelIndex &index);
};
To copy to clipboard, switch view to plain text mode
Controller
::Controller(QObject *parent
){
}
{
// could also install a custom delegate here and connect to it
}
void Controller::updateModel()
{
m_model->setQuery(...);
}
void Controller
::onCellClicked(const QModelIndex &index
) {
// do whatever needs to be done
}
Controller::Controller(QObject *parent)
: QObject(parent)
, m_model(new QSqlQueryModel(this))
{
}
void Controller::setView(QTableView *view)
{
connect(view, SIGNAL(clicked(QModelIndex)), this, SLOT(onCellClicked(QModelIndex)));
// could also install a custom delegate here and connect to it
}
void Controller::updateModel()
{
m_model->setQuery(...);
}
void Controller::onCellClicked(const QModelIndex &index)
{
// do whatever needs to be done
}
To copy to clipboard, switch view to plain text mode
Bookmarks