I have a class that has declared a static volatile QHash
class Sample
{
volatile static QHash <string, int> myDict;
}
And I am using a class to override the run() method of QThread
class MyThread : public QThread
{
public:
void run()
{
string s = "hello";
if(Sample::myDict.contains(s)){std::cout << "i contain "<< s;}
}
}
But doing this gives me a compilation error :
passing 'volatile QHash<std::string, int>' as 'this' argument of 'bool QHash<Key, T>::contains(const Key&) const [with Key = std::string; T = int]' discards qualifiers [-fpermissive]
So I checked on stack overflow. It seems that passing volatile variables to functions makes the compiler give a warning because compiler can do thread unsafe optimizations w.r.t that variable. But in my case, the compiler is giving an error instead of a warning. Also, here the volatile QHash seems to be an implicit argument to the function "QHash::contains". Any help?