Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator debugging - The values of all string variables in "Locals and Expressions" are Not Accessible

Qt Creator debugging - The values of all string variables in "Locals and Expressions" are Not Accessible

Scheduled Pinned Locked Moved Qt Creator and other tools
8 Posts 4 Posters 23.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Naalim
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gyll
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Naalim
        wrote on last edited by
        #3

        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_p

        and _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'"?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gyll
          wrote on last edited by
          #4

          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)

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Naalim
            wrote on last edited by
            #5

            Aight. Thanks for the solution though!

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andrep
              wrote on last edited by
              #6

              I don't think this is the correct solution. Displaying std::string (and all others) should work out-of-the box. Make sure to disable(!) the "Load system GDB pretty printers" checkbox in Tools->Options->Debugger->GDB to avoid external interferences.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                marek.jasovsky
                wrote on last edited by
                #7

                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&#40;&#41;;
                

                }

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andrep
                  wrote on last edited by
                  #8

                  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 &.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved