我正在尝试使用 QCache 类,但是缺少方法插入...
SqlTableModel.h
class SqlTableModel : public QSqlTableModel
{
Q_OBJECT
public:
Q_INVOKABLE QVariant getValue(QJSValue searchColumn, QJSValue searchValue, QJSValue returnColumn) const;
private:
QCache <QString, QString> m_cache;
};
sql.cpp ....
QVariant SqlTableModel::getValue(QJSValue columnName, QJSValue columnKey, QJSValue returnColumnName) const
{
QString cache_key;
cache_key = columnName.toString() + "_" + columnKey.toString() + "_" + returnColumnName.toString();
return m_cache.insert //?????????? auto complet=te give me nothing!
}
在尝试构建之后:
//error: 'this' argument to member function 'insert' has type 'const QCache<QString, QString>', but function is not marked const
//error: no matching function for call to ‘QCache<QString, QString>::insert(const char [10], QString&) const’
// return m_cache.insert("123123123", cache_key);
我的问题在哪里???
最佳答案
你的问题是 getValue
是 const
函数,而 QCache
的 insert
不是 const
。
您可以使您的函数成为非 const,或者将 m_cache
标记为 mutable
,或者为 insert 和 get 创建不同的函数。
关于c++ - QCache 没有方法插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53670291/