Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Something about qt creator debug

    General and Desktop
    4
    12
    5976
    Loading More Posts
    • 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.
    • H
      henryxuv last edited by

      If I have a code like this
      @void testFun()
      {
      int result = add(a, b);
      }@
      The value of 'result' cannot be watched when debugging. the qt creator hint me , that the variable 'result' is out of scopt when the program run to the end of this function. Consider this situation, I have to add a meaningless sentence to keep the 'result' still in scope and watch the 'result' value. Is this gdb problem or qt creator. How can I resolve it? The same code in msvc, I can see the 'result' value no doubt. This is not convinient for debugg.

      1 Reply Last reply Reply Quote 0
      • T
        tobias.hunger last edited by

        It is most likely neither the fault of creator nor gdb: The compiler will be optimizing out the variable. I am surprised that MSVC is supposedly not doing this.

        Try disabling optimizations in your compiler. You can also add a Q_UNUSED(result); after line 3 to discourage the compiler from using this optimization.

        1 Reply Last reply Reply Quote 0
        • H
          hardcodes.de last edited by

          Have you set a breakpoint in line 3? After leaving the function result is destroyed, there is nothing that can be watched afterwards.
          Or I do not get, what you really asked for ;-) And what is a and b?

          while(!sleep){++sheep;}

          1 Reply Last reply Reply Quote 0
          • H
            henryxuv last edited by

            Yes, you didn't get me . what is a and b is not the problem. the code I wrote is just a sample. The problem is , if a temporary variable declared at the end of a function. you will not able to watch the value of it when you debug the function in qt creator.

            [quote author="hardcodes.de" date="1368782030"]Have you set a breakpoint in line 3? After leaving the function result is destroyed, there is nothing that can be watched afterwards. Or I do not get, what you really asked for ;-) And what is a and b?[/quote]

            1 Reply Last reply Reply Quote 0
            • H
              henryxuv last edited by

              if my programe is released, the variable may be optimized out. But what I said is in debug mode, In my opinion , there is no optimization in debug mode. the macro Q_UNUSED doesn't work as I expected. I still can't watch the value of te variable at the end of function.

              [quote author="Tobias Hunger" date="1368782018"]It is most likely neither the fault of creator nor gdb: The compiler will be optimizing out the variable. I am surprised that MSVC is supposedly not doing this. Try disabling optimizations in your compiler. You can also add a Q_UNUSED(result); after line 3 to discourage the compiler from using this optimization.[/quote]

              1 Reply Last reply Reply Quote 0
              • JKSH
                JKSH Moderators last edited by

                I'm not sure what's going on with your GDB/Creator, but here's a different method you can try:
                @
                #include <QDebug>

                void testFun()
                {
                int result = add(a, b);
                qDebug() << result;
                }
                @

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply Reply Quote 0
                • H
                  henryxuv last edited by

                  Yes , qDebug is a good way. I want is not only a solution, I am interested in why this happen?

                  [quote author="JKSH" date="1368789354"]I'm not sure what's going on with your GDB/Creator, but here's a different method you can try: @ #include <QDebug> void testFun() { int result = add(a, b); qDebug() << result; } @[/quote]

                  1 Reply Last reply Reply Quote 0
                  • JKSH
                    JKSH Moderators last edited by

                    [quote author="henryxuv" date="1368789831"]Yes , qDebug is a good way. I want is not only a solution, I am interested in why this happen?[/quote]I don't know the answer; you'll have to ask someone else :) "Stack Overflow":http://stackoverflow.com/ is a good place to ask general software development questions. I think yours is a GDB issue, not a Qt Creator issue.

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply Reply Quote 0
                    • H
                      hardcodes.de last edited by

                      Maybe if you dump the generated object file, you can reproduce if the lines are actually there or optimized away.

                      while(!sleep){++sheep;}

                      1 Reply Last reply Reply Quote 0
                      • H
                        henryxuv last edited by

                        You are right, the variable has been optimizated out. I try to disable the optimization, but failed. Could you tell me a way to do that, I check my qmake.conf file under qt\mkspecs\win32-g++ directory. (because my platform is winxp). the QMAKE_CFLAGS is empty. without any flags for optimization.

                        [quote author="Tobias Hunger" date="1368782018"]It is most likely neither the fault of creator nor gdb: The compiler will be optimizing out the variable. I am surprised that MSVC is supposedly not doing this. Try disabling optimizations in your compiler. You can also add a Q_UNUSED(result); after line 3 to discourage the compiler from using this optimization.[/quote]

                        1 Reply Last reply Reply Quote 0
                        • H
                          hardcodes.de last edited by

                          Maybe the volatile keyword can help here although I'm not sure that the creators of C++ had that in mind.

                          Just out of curiosity: what is the goal of the whole thing?

                          while(!sleep){++sheep;}

                          1 Reply Last reply Reply Quote 0
                          • H
                            henryxuv last edited by

                            When I wrote program with Qt Creator, I find the situation which never happened in MSVC. So I wonder why? For me, this is a opportunity to know Qt and it's tools in detail. So I try to figure out the reason. Thank for all of you to help me .Now I have got the reason.
                            [quote author="hardcodes.de" date="1369330298"]Maybe the volatile keyword can help here although I'm not sure that the creators of C++ had that in mind.

                            Just out of curiosity: what is the goal of the whole thing?[/quote]

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post