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. [SOLVED]Object delete incorrect in the QThread
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Object delete incorrect in the QThread

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.1k 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.
  • H Offline
    H Offline
    hhacker
    wrote on last edited by
    #1

    Hi,
    I'm learning QThread from Qt Project website,and a few questions make me confused a lot,my code is very simple :
    @
    void open(QString servername){
    PipePiper *worker = new PipePiper(servername);
    worker->moveToThread(&workerThread);
    connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
    connect(this, SIGNAL(close()), worker, SLOT(deleteLater()));
    workerThread.start();
    }

    signals:
    void close(void);
    @
    I called open several times and I thought it will delete single one PipePiper object when signal close() was triggered,but it turns out it will delete all my workers which is absolutely not my purpose.
    Thanks for any advice.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hhacker
      wrote on last edited by
      #2

      oh,I see what problem is,signal close will trigger every worker->deleteLater.
      My way is totally wrong,but I still don't know how to fix it.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        msue
        wrote on last edited by
        #3

        Please look at the first example in the QThread docu (you can click on the green QThread class in your code above to get there): They have a Worker object (your PipePiper) and a Controller object (your outside class).

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hhacker
          wrote on last edited by
          #4

          [quote author="msue" date="1408084996"]Please look at the first example in the QThread docu (you can click on the green QThread class in your code above to get there): They have a Worker object (your PipePiper) and a Controller object (your outside class).[/quote]

          thanks,I fixed it,it may have a little memory leak but i will continue work on it.

          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