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. [moved] how to display a local variable in hex, when debugging a qt app
QtWS25 Last Chance

[moved] how to display a local variable in hex, when debugging a qt app

Scheduled Pinned Locked Moved Qt Creator and other tools
10 Posts 5 Posters 29.2k 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.
  • P Offline
    P Offline
    paa123456
    wrote on last edited by
    #1

    Hi ,
    This should be a simple issue however I did not find the way to solve it for several days.

    I am debugging a qt application and when I add local variables they all come in decimal form. My application is a low level one and to understand the results I need hexadecimal / hex results.

    Is this possible in qt?
    If possible - how do I set the debugger to display in hex?

    Thank you,
    Paul.

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

      This does the trick:

      @
      int x = 14948;
      QString xAsHex = QString("%1").arg(x, 0, 16);
      qDebug() << "x = " << x << " = " << xAsHex;
      // output:
      // x = 14948 = "3a64"
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        paa123456
        wrote on last edited by
        #3

        Hello Volker,
        Thank you for the quick replay.

        Certainly I can place a hex output - as a printf(), a messagebox, or qDebug , however the code will be 2-3 times the current size, just to get some info how it executes.

        I need to give some details -
        I am using qtcreator to build and debug an application.
        I start the app in debug mode - there are several areas showing functions, and next to them local variables and adding watch variables.
        Some of the functions come with hex addresses , however the locals and watches are decimal.
        The same is when I point the cursor to get info on variable as a tooltip.

        My question is how do I get this info as hex and not decimal?

        If this is not currently possible in 'qt' - it means that for the last 10-15 years it has not been used in low level development , and nobody did raise the issue with the development team.

        Thank you,
        Paul.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          Can't you just rightclick on the local you're interested in and set its format to hexadecimal?

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            [quote author="paa123456" date="1302476516"]Hello Volker,
            If this is not currently possible in 'qt' - it means that for the last 10-15 years it has not been used in low level development , and nobody did raise the issue with the development team.[/quote]

            Qt Creator, which you seem to be talking about, has indeed not been used for the last 10-15 years. For any kind of development. It is only a few (two or so?) years old, after all.

            The tools Qt builds on (compilers, debuggers, etc.) have existed for the time span you're talking about, and can probably do all you need it to do.

            1 Reply Last reply
            0
            • JohanSoloJ Offline
              JohanSoloJ Offline
              JohanSolo
              wrote on last edited by
              #6

              Wouldn't be

              @int x = 14948;
              qDebug() << "x = " << x << " = " << std::hex << x;
              @

              easier?

              [quote author="Volker" date="1302472389"]This does the trick:

              @
              int x = 14948;
              QString xAsHex = QString("%1").arg(x, 0, 16);
              qDebug() << "x = " << x << " = " << xAsHex;
              // output:
              // x = 14948 = "3a64"
              @[/quote]

              `They did not know it was impossible, so they did it.'
              -- Mark Twain

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                [quote author="JohanSolo" date="1302510723"]Wouldn't be

                @int x = 14948;
                qDebug() << "x = " << x << " = " << std::hex << x;
                @

                easier?
                [/quote]

                No, it's output is

                @
                // x = 14948 = true 14948
                @

                But this does the trick too:

                @
                // no std:: before the hex
                qDebug() << "x1 = " << x << " = " << hex << x;
                @

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                1
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  [quote author="paa123456" date="1302476516"]
                  I need to give some details -
                  I am using qtcreator to build and debug an application.
                  I start the app in debug mode - there are several areas showing functions, and next to them local variables and adding watch variables.
                  Some of the functions come with hex addresses , however the locals and watches are decimal.[/quote]

                  It would be helpful, if you gave those informations in the first place. The crystal ball is out of work on weekends, you know :-) Qt is not Qt Creator. You can use the first without the second. We would have given you the right solution directly.

                  The way peppe described works.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    paa123456
                    wrote on last edited by
                    #9

                    peppe wrote -

                    Can’t you just rightclick on the local you’re interested in and set its format to hexadecimal?

                    Yes, rightclick 'change format for type' does work in qtcreator - however for basic types only.
                    If I have -
                    #define DWORD unsigned int
                    the right click 'change format for type' for DWORD watch/variable is disabled in qtcreator.
                    Is there a way to make it working for defined types?

                    Well , at least I got something to help with debugging.

                    Thank you ,
                    Paul.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dangelog
                      wrote on last edited by
                      #10

                      Ask on IRC on the #qt-creator channel; all in all, creator knows how to nicely show Qt datatypes, therefore there must be a way to do that with arbitrary datatypes.

                      Apart from this, use a typedef, not a define :)

                      Software Engineer
                      KDAB (UK) Ltd., a KDAB Group company

                      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