sashoalm
sashoalm

Reputation: 79467

Qt Creator debugger doesn't show text contents of char* and wchar_t* variables

Qt Creator does not show char* or wchar_t* variables as strings, while std::string and std::wstring are shown correctly.

For example for this code:

const char *a = "abcd";
const wchar_t *b = L"abcd";
std::string c = "abcd";
std::wstring d = L"abcd";

The debuger's Watch Window shows this:

enter image description here

As you can see, c and d are shown as text, but a and b are treated like regular pointers.

Is there a setting that can make it show char* and wchar_t* the same way it shows std::string and std::wstring?

Upvotes: 2

Views: 2470

Answers (1)

Nikos C.
Nikos C.

Reputation: 51840

You have to keep in mind that a char* is a pointer to a char. It's not a string by definition; it's just a pointer to a char. So the debugger can't really assume that it's a string, unless you explicitly tell it to. To do that, right click on it in the watch window, select "change local display format", and there you can change how the debugger should interpret either just this one variable or all char* pointers.

Upvotes: 3

Related Questions