Answer the question
In order to leave comments, you need to log in
Why discards qualifiers?
I am writing a model inherited from abstract QAbatractTableModel
. Everything according to Feng Shui, methods, everything that needs to be rewritten. But I decided to cache the data in the cache
. Therefore, you need to change the method data
and setData
. As a result, it turned out:
QVariant MyModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return QVariant();
if (!cache.contains(m_course)) {
QMap<QDate, Week> weeks;
Week week;
QVector<ScheduleItemPrintable> day;
for (int nDay = 0; nDay < 7; ++nDay) {
for (int nDoublePeriod = 0; nDoublePeriod < 6; ++nDoublePeriod)
day << ScheduleItemPrintable();
week << day;
}
weeks.insert(m_monday, week);
cache.insert(m_course, weeks); // ошибка
}
//...
}
class MyModel : public QAbstractTableModel
{
Q_OBJECT
private:
QStringList hheader;
typedef QVector<QVector<ScheduleItemPrintable> > Week;
QMap<QString, QMap<QDate, Week> > cache;
QString m_course;
QDate m_monday;
public:
explicit MyModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role);
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
};
error: passing
'const QMap<QString, QMap<QDate, QVector<QVector<ScheduleItemPrintable> > > >'
as 'this' argument of 'QMap<Key, T>::iterator QMap<Key, T>::insert(const Key&, const T&)
[with Key = QString; T = QMap<QDate, QVector<QVector<ScheduleItemPrintable> > >]'
discards qualifiers [-fpermissive] cache.insert(m_course, weeks);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question