c++ - QCache 没有方法插入

标签 c++ qt

我正在尝试使用 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);

我的问题在哪里???

最佳答案

你的问题是 getValueconst 函数,而 QCacheinsert 不是 const

您可以使您的函数成为非 const,或者将 m_cache 标记为 mutable,或者为 insert 和 get 创建不同的函数。

关于c++ - QCache 没有方法插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53670291/

相关文章:

c++ - 为什么我会收到 glibc 错误?

c++ - 使用 STL sort() 对 char 指针进行排序

c++ - 如何将数字直接写入 ofstream 对象?

qt - 如何在点击时加载 QML 组件

c++ - 为什么我的 QRadioButtons 没有出现在我的 QGroupBox 中?

c++ - 对在Boost.statechart中完成的所有正交状态使用react

c++ - 重载流和算术运算问题

c++ - 如何使下级类调用其父级的方法?

c++ - VTK + Cmake-> USE_VTK_RENDERING错误

QT:隐藏对话框/窗口的标题栏