User forums > Using Code::Blocks
Debugging QString
LordCB:
Hello friends,
during programming with Qt in CB I watch QStrings in this manner during debugging
--- Code: ---QString qTest = qstrLine;
std::string strTest = qTest.toStdString();
--- End code ---
Is there a more convinient way to do this. Is there a direct watch method.
I don“t like to insert code to watch some variables during debugging and it is more to do;
oBFusCATed:
You could add a debugger script to parse the QStrings.
For more info see here: http://wiki.codeblocks.org/index.php?title=Debugger_scripts
LordCB:
Ok, ...
--- Code: ---function RegisterTypes(driver)
{
// signature:
// driver.RegisterType(type_name, regex, eval_func, parse_func);
// QString
driver.RegisterType(
_T("Qt String"),
_T("[^[:alnum:]_]*QString[^[:alnum:]_]*"),
_T("Evaluate_QString"),
_T("Parse_QString")
);
Log(_T("RegisterTypes is being called"));
}
function Evaluate_QString(type, a_str, start, count)
{
//what to do???
return a_str;
}
function Parse_QString(a_str, start)
{
//what to do???
return a_str;
}
--- End code ---
Hmm and now any suggestions...
where comes my qstring variable in. The a_str seems to be a std::string.
oBFusCATed:
--- Code: ---function Evaluate_QString(type, a_str, start, count)
--- End code ---
a_str is the string you have written in the watch windows (my_string, str, my_struct.name, etc).
In this function you are supposed to generate a command that gdb can execute and produce some output you can parse in the
Parse_QString function.
--- Code: ---function Parse_QString(a_str, start)
--- End code ---
Here a_str is the result of the gdb command, just executed.
For example if you have 'QString s = "test"', you want to execute something like "output s.m_pinternal_string" and if the result is "test" in the parse function you return the a_str directly because it doesn't need any parsing and conversion.
Look for file gdb_types.script, there you can see implementations for some types: std::string, wxstring and std::vector
eranif:
This is how I debug QString:
I add the following user function to the debugger on the startup:
--- Code: ---define printqstring
printf "(QString)0x%x (length=%i): \"",&$arg0,$arg0.d->size
set $i=0
while $i < $arg0.d->size
set $c=$arg0.d->data[$i++]
if $c < 32 || $c > 127
printf "\\u0x%04x", $c
else
printf "%c", (char)$c
end
end
printf "\"\n"
end
--- End code ---
Next, to view QString, I simply type:
--- Code: ---printqstring <variable_name>
--- End code ---
I guess that CodeBlocks can automate this procedure for you (i.e. register the user function when debugging session starts and to choose the command 'printqstring' over 'print' when a tooltip is requested)
Eran
Navigation
[0] Message Index
[#] Next page
Go to full version