Reputation: 12323
I have a function that needs to access the value of a qmap pointer object.
void SomeClass::SomeFunction(QMap<qint64, bool>* times, qint64 startPoint, qint64 endPoint)
{
//Here I want to check the value at an existing index.
}
What I tried:
times[key];
and:
×[key];
and:
×[key] == 0;
Both give a wrong result (the value is true but i am expecting false).
Upvotes: 0
Views: 1272
Reputation: 48258
in qt the qmap has a method for that: contains
times->contains(startPoint)
so the way to go would be:
if (times->contains(startPoint))
{
....
}
update:
to get the value of the pointer you need to be aware of the operator precedence i.e. you have to do:
std::map<int, bool>*x = new std::map<int, bool>();
x->insert ( std::pair<int, bool>(0,false) );
x->insert ( std::pair<int, bool>(5,true) );
bool flag = (*x)[0];
std::cout << "at 0: " << flag << std::endl;
flag = (*x)[5];
std::cout << "at 5: " << flag << std::endl;
so in your case
bool flag = (*times)[startPoint];
Upvotes: 1