Reputation: 162
I'm in an enterprise environment (which means there's no possibility a priori to add pretty printers or change software at any level) using GDB (gdbserver) to debug an app using Qt on a different device.
While I'm debugging, I usually need to check the values of a Qt structure like a QMap, which has a QString as key.
Guess I have a map like this one:
QVariantMap map;
Now, while debugging, that happens:
(gdb) p dataMap.value()
Too few arguments in function call.
(gdb) p dataMap.value("first")
Cannot resolve method QVariantMap::value to any overloaded instance
(gdb) p dataMap.value("first", QVariant(""))
A syntax error in expression, near `(""))'.
According to QMap documentation, both 2nd and 3rd options should work.
That's pretty annoying, since I'd love to be able to check map's values without modifying my code.
It seems to me that there's some kind of missunderstanding between GDB and Qt.
Any help would be appreciated.
EDIT:
As pointed out by Mohammed, gdb doesn't have to understand conversion from const char *
to QString
.
It doesn't make any difference however, since I get the same error when I use QString("")
than this one seen in the third command of the original part with QVariant("")
.
(gdb) p params.value(QString("deliveryLimit"))
A syntax error in expression, near `"deliveryLimit"))'
In this case, it is a QHash, but this shouldn't be important since I'm looking for a way to debug Qt's value-key containers in general.
Upvotes: 0
Views: 795
Reputation: 4050
First of all, lets use QVariantMap for QMap<QString, QVariant>
.
Posible issues: gdb is not a compiler, so let's avoid user-defined type conversions for you. Function wich wants a QString, lets give it a QString, not a const char*.
(gdb) p dataMap.value(QString("first"))
To avoid future problem, use a little helper function to your program, that would take a const char* and return an QString&, something like:
QString& toQString(const char* s)
{
return *(new QString(s));
}
Then in gdb
gdb> p dataMap.value(toQString("domain"));
Fast solution, use QMap<const char*, QVariant>
Upvotes: 0