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. Quit and delete thread
Forum Updated to NodeBB v4.3 + New Features

Quit and delete thread

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 6.5k 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.
  • R Offline
    R Offline
    Ruzik
    wrote on 3 Aug 2011, 11:10 last edited by
    #1

    Hellow, i have one problem:
    I have many threads and when i finished thread i want to delete it, but if i write
    @void myThread::getDeleteAndQuit() //slot
    {
    this->exit(0);
    delete this;
    }@
    and coll it that i have error, why?
    I dont use some slots and everything should be done linearly
    I have no way of storing pointers to the threads
    Advance many thanks for your help!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 3 Aug 2011, 11:14 last edited by
      #2

      You delete your self. I assume, you do it inside run, right? but run is only a method, called by QThread methods. after the delete, the call stack returns to the calling function (e.g. run) and the to the caller of run, which might access members of QThread, which you deleted.

      EDIT: exit justs exits, the event loop

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ruzik
        wrote on 3 Aug 2011, 11:45 last edited by
        #3

        How can i edit it?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ruzik
          wrote on 3 Aug 2011, 12:21 last edited by
          #4

          bq. I assume, you do it inside run, right?

          No, this slot i called from other slot, which causes signal

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Ruzik
            wrote on 3 Aug 2011, 12:31 last edited by
            #5

            This is my run()
            @void myThread::run()
            {
            findNext();
            exec();
            }@
            findNext() is function witch called connected slot and signal, and when slot was called, it called getDeleteAndQuit() as function

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on 3 Aug 2011, 12:32 last edited by
              #6

              Now I get confused. Who calls what when?
              exit will cause the event loop to stop, but not synchronously. The thread has not finished then.
              perhaps the wait trick helps you:

              @
              void myThread::getDeleteAndQuit() //slot
              {
              this->exit(0);
              this->wait(); // <-- wits till the thread has exited
              deleteLater(); // <-- ensures that it will be deleted later when the (main?) event loop executes again
              }
              @

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Ruzik
                wrote on 3 Aug 2011, 13:56 last edited by
                #7

                It is help me!
                Thank you for your help!

                1 Reply Last reply
                0

                1/7

                3 Aug 2011, 11:10

                • Login

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