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. Pthread and Gui wont work together
Qt 6.11 is out! See what's new in the release blog

Pthread and Gui wont work together

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 2 Posters 7.0k Views 1 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.
  • D Offline
    D Offline
    degens
    wrote on last edited by
    #3

    Yes, the Mainwindow works just find, can click it and all, so that one responds well.

    mrjjM 1 Reply Last reply
    0
    • D degens

      Yes, the Mainwindow works just find, can click it and all, so that one responds well.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @degens
      And that is also after you call void connection() ?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        degens
        wrote on last edited by
        #5

        That's correct, the gui parts works just fine. Can click my buttons and they change values and so on.

        mrjjM 1 Reply Last reply
        0
        • D degens

          That's correct, the gui parts works just fine. Can click my buttons and they change values and so on.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #6

          @degens
          Ok so we can be sure the main event loop is running.
          So issue must be with thread.

          is the
          while(1){
          results = recv(xxx)

          being run?

          Also, just be be 100% sure

          pthread_t threads[NUM_THREADS]; << local variable
          xx
          pthread_create(&threads[0], NULL, recvieveMsg, (void *)socket);

          so when connection() ends, the threads[NUM_THREADS] will be deleted.
          Is that intentional ?

          Just asking that it should only live as long as inside connection() and not longer.

          1 Reply Last reply
          1
          • D Offline
            D Offline
            degens
            wrote on last edited by
            #7

            No that is not intentional, but when the conneciton() is done, shouldn't the thread still be running until I "kill" it? I mean, how would you otherwise use threads?

            mrjjM 1 Reply Last reply
            0
            • D degens

              No that is not intentional, but when the conneciton() is done, shouldn't the thread still be running until I "kill" it? I mean, how would you otherwise use threads?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #8

              @degens
              Yes, it should be running, but we give it pointer to this structure
              http://man7.org/linux/man-pages/man3/pthread_create.3.html
              and its silently deleted a moment after.
              So Im not sure if it will upset the thread or not. Just asking. :)

              Also did you check the return code from pthread_create?

              1 Reply Last reply
              0
              • D Offline
                D Offline
                degens
                wrote on last edited by
                #9

                Alright this is really weird. I did a printf on my connection() function, and it didn't print out anything, only when I closed my program. So it seems like the functions is not even executed when running main, only when I close...

                Thanks for the help btw! :)

                mrjjM 1 Reply Last reply
                0
                • D degens

                  Alright this is really weird. I did a printf on my connection() function, and it didn't print out anything, only when I closed my program. So it seems like the functions is not even executed when running main, only when I close...

                  Thanks for the help btw! :)

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #10

                  @degens
                  Ok that sounds a bit strange. :)
                  Have you tried the debugger ? single stepping and see what is actually being run.
                  Or set a break point and start.

                  Update: Wait, missin gprintf can be other issue
                  http://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin

                  try with
                  printf("test!");
                  fflush(stdout);

                  1 Reply Last reply
                  2
                  • D Offline
                    D Offline
                    degens
                    wrote on last edited by
                    #11

                    Ha! The problem was lying right in front of me... Now I get the output I wanted, thank you very much for your help! Will definitely ask here again if something else comes up, even though I'm a Java Developer. ;)

                    mrjjM 1 Reply Last reply
                    1
                    • D degens

                      Ha! The problem was lying right in front of me... Now I get the output I wanted, thank you very much for your help! Will definitely ask here again if something else comes up, even though I'm a Java Developer. ;)

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @degens
                      Super :)
                      I think Qt + application sets up buffer so thats why it stopped printing once it became
                      part of Qt project.
                      You are always welcome to come ask here. Its a user orientated forum and many other also use
                      Java so its also good place to ask. "In java, i can write this, how can i do same in Qt". Kind of questions.

                      1 Reply Last reply
                      1

                      • Login

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