Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Debugging a Thread in Qt Creator
Forum Updated to NodeBB v4.3 + New Features

Debugging a Thread in Qt Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 6 Posters 14.6k Views 3 Watching
  • 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #13

    From Jasmin Blanchette, Mark Summerfield, C++ GUI Programming with Qt 4 Chapter 18, Pragraph "Communicating with the Main Thread"

    When a Qt application starts, only one thread is runningthe main thread. This is the only thread that is allowed to create the QApplication or QCoreApplication object and call exec() on it. After the call to exec(), this thread is either waiting for an event or processing an event.

    This is what put that concept into my mind. I very well admit it might not be the case, wouldn't be the first time that manual was wrong

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    1 Reply Last reply
    1
    • K Offline
      K Offline
      kumararajas
      wrote on last edited by
      #14

      Thanks for the discussions on GUIThread vs main thread.

      However, does it stops me debugging?

      Thanks!
      Kumara

      --Kumar

      JKSHJ 1 Reply Last reply
      0
      • kshegunovK kshegunov

        Try disabling "Run in terminal" in Qt creator if you haven't tried that. Recently I posted encountered a bug on the tracker that corresponds to the behaviour you're describing.

        Edit: Original thread with the corresponding bug report https://forum.qt.io/topic/74646/qt-creator-fails-to-map-breakpoints-sometimes

        K Offline
        K Offline
        kumararajas
        wrote on last edited by
        #15

        @kshegunov said in Debugging a Thread in Qt Creator:

        Try disabling "Run in terminal" in Qt creator if you haven't tried that. Recently I posted a bug on the tracker that corresponds to the behaviour you're describing.

        I am gonna try this now and get back to you with the results.

        Thanks for the thoughts!

        --Kumar

        1 Reply Last reply
        0
        • K kumararajas

          Thanks for the discussions on GUIThread vs main thread.

          However, does it stops me debugging?

          Thanks!
          Kumara

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #16

          @VRonin said in Debugging a Thread in Qt Creator:

          @kshegunov Probably a linguistic mistake on my part but that's how I read that paragraph. I think some platforms (Windows?) force that restriction

          I think that paragraph is poorly-written. On Windows and Linux, you can use a non-main thread as your GUI thread. macOS is the one that has the restriction. See http://stackoverflow.com/questions/22289423/how-to-avoid-qt-app-exec-blocking-main-thread/22290909#22290909

          (Side note: LQ Widgets spawns a non-main GUI thread. If you're interested in the details, see startWidgetEngine() and run() in https://github.com/JKSH/LQWidgets/blob/master/src/Cpp/lqmain.cpp )

          @kumararajas said in Debugging a Thread in Qt Creator:

          Thanks for the discussions on GUIThread vs main thread.

          However, does it stops me debugging?

          Good question; I don't know the answer. Please let us know your results.

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

          kshegunovK 1 Reply Last reply
          2
          • JKSHJ JKSH

            @VRonin said in Debugging a Thread in Qt Creator:

            @kshegunov Probably a linguistic mistake on my part but that's how I read that paragraph. I think some platforms (Windows?) force that restriction

            I think that paragraph is poorly-written. On Windows and Linux, you can use a non-main thread as your GUI thread. macOS is the one that has the restriction. See http://stackoverflow.com/questions/22289423/how-to-avoid-qt-app-exec-blocking-main-thread/22290909#22290909

            (Side note: LQ Widgets spawns a non-main GUI thread. If you're interested in the details, see startWidgetEngine() and run() in https://github.com/JKSH/LQWidgets/blob/master/src/Cpp/lqmain.cpp )

            @kumararajas said in Debugging a Thread in Qt Creator:

            Thanks for the discussions on GUIThread vs main thread.

            However, does it stops me debugging?

            Good question; I don't know the answer. Please let us know your results.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #17

            @JKSH said in Debugging a Thread in Qt Creator:

            Side note: LQ Widgets spawns a non-main GUI thread.

            You have a race condition on initialization, though ... you should switch Bridge * to QAtomicPointer<Bridge>, since at lines 32 and 57 you touch the pointer from different threads. By the way, what's the problem with using a semaphore to wait for the GUI thread, I really dislike that while (!bridge) line ...

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            3
            • kshegunovK kshegunov

              Try disabling "Run in terminal" in Qt creator if you haven't tried that. Recently I posted encountered a bug on the tracker that corresponds to the behaviour you're describing.

              Edit: Original thread with the corresponding bug report https://forum.qt.io/topic/74646/qt-creator-fails-to-map-breakpoints-sometimes

              K Offline
              K Offline
              kumararajas
              wrote on last edited by
              #18

              @kshegunov said in Debugging a Thread in Qt Creator:

              Try disabling "Run in terminal" in Qt creator if you haven't tried that. Recently I posted encountered a bug on the tracker that corresponds to the behaviour you're describing.

              Hi,

              I did give a try with this approach. Still no success on not hitting the breakpoint in thread..

              --Kumar

              kshegunovK 1 Reply Last reply
              0
              • K Offline
                K Offline
                kumararajas
                wrote on last edited by
                #19

                And here is one observation on Qt Application being on main thread vs worker thread.

                When you run Qt application on a main thread, you don't create the thread by yourself, so you don't need to worry about the thread parameters which has been used by Qt internally.

                When we create Qt application on a thread, we are suppose to take care of thread parameters.

                Example, thread stack size. If you don't set it by yourself, then the linux default stack size for the thread is 2MB. Which will be used for your Qt thread.
                And the challenge here is, we don't know what should be the stack size for Qt. We may overrun during long run, so we should keep that in mind. And the challenge is Qt never tell us on how much should be set.

                I have observed this just today morning. I have set my stack size to 64k and the application was coming up and getting exited in few seconds with segmentation fault error. When I have increased to 128K, application was up for a while, but it crashed later on. Now, I have 256K, which looks good but I never know when it will crash.

                Having the stack size challenge aside, I don't think any problem on Qt being on a worker thread.

                --Kumar

                1 Reply Last reply
                0
                • K kumararajas

                  @kshegunov said in Debugging a Thread in Qt Creator:

                  Try disabling "Run in terminal" in Qt creator if you haven't tried that. Recently I posted encountered a bug on the tracker that corresponds to the behaviour you're describing.

                  Hi,

                  I did give a try with this approach. Still no success on not hitting the breakpoint in thread..

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #20

                  @kumararajas said in Debugging a Thread in Qt Creator:

                  I did give a try with this approach. Still no success on not hitting the breakpoint in thread..

                  Well, what about the debugger log? It should shed some light on the issue.

                  When we create Qt application on a thread, we are suppose to take care of thread parameters.

                  Not really, no.

                  Example, thread stack size. If you don't set it by yourself, then the linux default stack size for the thread is 2MB.

                  Which is perfectly fine, I wouldn't mess with the stack size for no good reason.

                  Now, I have 256K, which looks good but I never know when it will crash.

                  Then just leave it to the OS!

                  Read and abide by the Qt Code of Conduct

                  K 1 Reply Last reply
                  2
                  • kshegunovK kshegunov

                    @kumararajas said in Debugging a Thread in Qt Creator:

                    I did give a try with this approach. Still no success on not hitting the breakpoint in thread..

                    Well, what about the debugger log? It should shed some light on the issue.

                    When we create Qt application on a thread, we are suppose to take care of thread parameters.

                    Not really, no.

                    Example, thread stack size. If you don't set it by yourself, then the linux default stack size for the thread is 2MB.

                    Which is perfectly fine, I wouldn't mess with the stack size for no good reason.

                    Now, I have 256K, which looks good but I never know when it will crash.

                    Then just leave it to the OS!

                    K Offline
                    K Offline
                    kumararajas
                    wrote on last edited by
                    #21

                    @kshegunov said in Debugging a Thread in Qt Creator:

                    Well, what about the debugger log? It should shed some light on the issue.

                    Where can I find the debugger log?

                    And for other answers, excellent. That convinces me!

                    Kumara

                    --Kumar

                    kshegunovK 1 Reply Last reply
                    0
                    • K kumararajas

                      @kshegunov said in Debugging a Thread in Qt Creator:

                      Well, what about the debugger log? It should shed some light on the issue.

                      Where can I find the debugger log?

                      And for other answers, excellent. That convinces me!

                      Kumara

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #22

                      @kumararajas said in Debugging a Thread in Qt Creator:

                      Where can I find the debugger log?

                      Window > Views > Debugger Log

                      Read and abide by the Qt Code of Conduct

                      K 1 Reply Last reply
                      0
                      • kshegunovK kshegunov

                        @kumararajas said in Debugging a Thread in Qt Creator:

                        Where can I find the debugger log?

                        Window > Views > Debugger Log

                        K Offline
                        K Offline
                        kumararajas
                        wrote on last edited by
                        #23

                        @kshegunov said in Debugging a Thread in Qt Creator:

                        Window > Views > Debugger Log

                        Did you mean debug window?

                        I don't see any on the debug window.

                        I use Qt Creator 3.2.2, which does not contain "Views" menu.

                        --Kumar

                        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