Qt Creator debugging - The values of all string variables in "Locals and Expressions" are Not Accessible
-
If I try to debug my C++ program in QT Creator the Locals and Expressions window shows me the variables in the program. However all the values show "< not accessible >".
Screenshot:
!http://i.stack.imgur.com/QY2ME.png()!
How do I get the values to show? I can print the values out with cout so I know they are initialized.
Seems like it only applies to strings. I create an int and it shows that value.
Specs/other:
Windows 8, 64bit
QT 5.2.0
MinGW 32bit, I think 4.8
QT Creator 3.0.0 -
For composite types (std::string and other classes) it doesn't automatically convert to some default type (e.g. std::string to char*); so what you need to do it right-click on a value, then select the submenu Change local display format-> Raw structure, and then keep opening the symbol until you get something meaningful (when possible). E.g. for std::string, after you change to "Raw structure", you get your actual string (by clicking the "+" sign to the left of your symbol) in: _M_dataplus->_M_p
Note that you can "Change local display format" for one symbol (the one you selected) or for all symbols of that type (e.g. you select a std::string, then all std::strings change to Raw structure)
PS
Also note that there's a lagging bug that's been in creator for ever but nobody cares to fix it, and the column widths do not automatically adjust even if you set them to. What you need to do to adjust the width of a column is to just click once on the column header and you're there. -
Thanks, that worked!
Do you know of any way of setting the meaningful symbol as the default?
When I set it as a raw structure the structure is, as you said,
StringName->_M_dataplus->_M_pand _M_p is the one containing the string value. Is there any way of setting _M_p to be shown instead of the whole structure tree? So that, just as a variable is shown "integerName | 5" then the string would be shown as "stringName/_M_p | 'hello world'"?
-
Nopse, dunno of any such thing. It would be nice to be able to set a default conversion for types (so you'd add "for std::string make default stringName->_M_dataplus->_M_p), but no such thing as far as i know. I'll file a suggestion for this, maybe somebody will care (yes, it is darn annoying to keep browsing through data structures)
-
-
Hello
I have noticed that this happens in a class constructor, that QString type parameters are not resolved, as soon as I make the same with plain method, then the parameter values are shown.
below see example which can reproduce this error.
class test2 {
private:
QString str1;public:
test2(QString str) {
str1 = str; // str is not accessible in debugger
}void set(QString str) { str1 = str; //str is visible in debugger, value is displayed correctly }
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
test2 *tt = new test2("test");
tt->set("test2");
tt->set("test3");return a.exec();
}
-
I can reproduce this, even with command-line gdb:
(gdb) p *str.d
yields
$3 = {<QArrayData> = {ref = {atomic = {_q_value = 135154040 } } ,
size = 134905058 , alloc = 1 , capacityReserved = 0 , offset = -1073745292 , ...}Note the unrealistic 'size' and 'alloc' values.
So either gdb does not read debug information properly (unlikely) or the compiler produced wrong debug info, possible due to applying some optimization without adjusting debug information
(more likely, happened in the past, see e.g. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44731)There is really nothing Qt Creator can do in this case.
Note also that the problem does not appear when passing the parameter as const &.