Unsolved How to get source QAbstractTableModel from QSortFilterProxyModel
-
class myModel : public QAbstractTableModel
{
Q_OBJECT
public:
myModel();
private:
string lists;
}class myProxyModel: public:QSortFilterProxyModel {
public:
virtual QVariant headerData(int column ,Qt::Orientation orientation, int role) const;
};class myWIndow: QWidget {
createWindow();private:
myProxyModel windowProxyModel;
myModel windowModel;}
void myWindow:createWindow() {
QTableView* view = new QTableView();
windowModel = new myModel();
windowProxyModel = new myProxyModel();
windowProxyModel ->setSourceModel(windowModel );
view->setModel(windowProxyModel);}
/* since we want the *to display headers in the tableview */
QVariant windowProxyModel ::headerData(int section ,Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && (orientation == Qt::Horizontal) ) {
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
I want to access myModel ->lst varaible (string)}
if (role == Qt::DisplayRole && (orientation == Qt::Vertical)) {
return section;
}
return QVariant();
}Could someone how to guide how access member of source (QAbstractTableModel) from ProxMode ?
-
@Qt-Enthusiast said:
You can get the models' model with
http://doc.qt.io/qt-5/qabstractproxymodel.html#sourceModelTo get a myModel from it. you will need to qobject_cast it
then you can access Public variables.