When I try to do this it segfaults and I'm not sure if it's because I'm missing a function or what, but here's a simplistic version of what I tried to do...oh and it segfaults even when I comment out filterAcceptsRow...
MySortFilterProxyModel.h
#include <QtGui/QSortFilterProxyModel>
{
Q_OBJECT
public:
MySortFilterProxyModel
(QObject *parent
= 0);
protected:
bool filterAcceptsRow
(int sourceRow,
const QModelIndex &sourceParent
) const;
};
#include <QtGui/QSortFilterProxyModel>
class MySortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
MySortFilterProxyModel(QObject *parent = 0);
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
};
To copy to clipboard, switch view to plain text mode
MySortFilterProxyModel.cpp
#include "MySortFilterProxyModel.h"
#include <iostream>
{
}
bool MySortFilterProxyModel
::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent
) const {
QModelIndex index0
= sourceModel
()->index
(sourceRow,
0, sourceParent
);
std::cout << "Index: " << sourceModel()->data(index0).toString().toStdString() << std::endl;
}
#include "MySortFilterProxyModel.h"
#include <iostream>
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
{
}
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
std::cout << "Index: " << sourceModel()->data(index0).toString().toStdString() << std::endl;
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
To copy to clipboard, switch view to plain text mode
MainWindow.cpp
...
MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel();
proxyModel->setSourceModel(dirModel); // SEGFAULTS
QDirModel *dirModel = new QDirModel();
MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel();
proxyModel->setSourceModel(dirModel); // SEGFAULTS
To copy to clipboard, switch view to plain text mode
...
Any ideas?
Bookmarks