Important: Please read the Qt Code of Conduct -

Wrong char type detection in debugger

  • Hi,
    I cannot make Qt Creator debugger view to correctly detect my char types when the type is behind a typedef.
    I made tests with char *, gchar *, and a custom mychar *, but Qt Creator only detects and shows the text contents for the very first case; it fails to show the other two. Is this a bug?

    Tested with this minimal program:


    #include <stdio.h>
    #include <glib.h>
    int main() {
      typedef char mytype;
      char *text1 = "TEXT1\n";
      gchar *text2 = "TEXT2\n";
      mytype *text3 = "TEXT3\n";
      return 0;


    cmake_minimum_required(VERSION 2.8)
    add_executable(${PROJECT_NAME} "main.c")
    find_package(PkgConfig REQUIRED)
    pkg_search_module(GLIB REQUIRED glib-2.0)
    target_include_directories(${PROJECT_NAME} PRIVATE ${GLIB_INCLUDE_DIRS})
    target_link_libraries(${PROJECT_NAME} INTERFACE ${GLIB_LDFLAGS})

    Setting a breakpoint on the last line, this is what I see in the debugger view:

    Name   Value        Type
    text1  "TEXT1\n"    char *
    text2  'T' 84 0x54  gchar
    text3  84           mytype

    Note that gchar is typedef char gchar; in glib/gtypes.h. However for some reason it is shown differently than my own typedef.

    My conclusion is that Qt Creator is unable to "see through" the typedef, and fails to detect:

    • That the types are actually pointer types. E.g. it should show gchar * instead of gchar.
    • That the types are actually just printable char arrays. It should show their contents, just as in the case of char *.

    I have tried a lot of permutations regarding the configuration, such as:

    • In the debugger view, trying different Display Formats for each variable and each type.
    • Enabling/Disabling Load system GDB pretty printers in the GDB options tab.
    • Enabling/Disabling Use Debugging Helper and Use code model in the Locals & Expressions options tab.
    • Repeating all previous tests with the Clang Code Model enabled/disabled.

    None of these tests changed the outcome.

    In the end, the only workaround that has worked is to create an Expression Evaluator for each variable, and apply an explicit cast to (char *). But this is clunky and very undesirable (I wouldn't want to do this for each and every variable!).

    Version information:

    • Linux Mint 18.3 Sylvia (Ubuntu 16.04 "Xenial")
    • GCC 5.4.0
    • Clang 5.0.0-3~16.04.1
    • GDB 7.11.1
    • Qt Creator 4.6.0

  • The problem is still valid with recent QtCreator 4.9.
    Does anyone have a solution? Has anyone reported this to the bug tracker?

  • Lifetime Qt Champion

    @Sergey-I. said in Wrong char type detection in debugger:

    Has anyone reported this to the bug tracker?

    I don't know. Did you check that?

Log in to reply