给自定义控件中的 全局变量赋值 为何会报错呢?
treemodel.h
public:
QVariant data(const QModelIndex & index, int role) const;
private:
QString strServerPath;
treemodel.cpp
QVariant TreeModel::data(const QModelIndex & index, int role = Qt::DisplayRole) const
{
strServerPath="aaa";
}
想给全局变量 strServerPath赋值 为 aaa, 结果报错:
error: passing 'const QString' as 'this' argument of 'QString& QString::operator=(const char*)' discards qualifiers [-fpermissive]
strServerPath="aaa";
^
如果去掉const 就有会报错,但无const 整个 QVariant data(const QModelIndex & index, int role) 函数就无效,
请求高人指点。