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

QThread signals wont work

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k 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.
  • G Offline
    G Offline
    glararan
    wrote on last edited by
    #1

    Hi,

    I calculating model and without about 16 threads Im post for few hours. My problem is that receiving function is not called.

    My code
    @ QThread* thread = new QThread();

                                FaceWorker* worker = new FaceWorker(vertexs, i);
                                worker->moveToThread(thread);
    
                                connect(thread, &QThread::finished, worker, &FaceWorker::deleteLater);
                                connect(this, &Face::operate, worker, &FaceWorker::doWork);
                                connect(worker, &FaceWorker::resultReady, this, &Face::handleResults);
    
                                thread->start();@
    

    handleResults is not called

    @void Face::handleResults(int threadID)
    {
    qDebug() << "thread" << threadID << "has done its work";
    }@

    @void FaceWorker::doWork()
    {
    qDebug() << "emiting results" << threadNumber;

    emit resultReady( threadNumber);
    

    }@
    This is called ok

    @
    class Face : public QObject
    {
    Q_OBJECT

    public:
    Face(QObject* parent = NULL);
    ~Face();

    void optimalize();
    

    public slots:
    void handleResults(int threadID);

    signals:
    void operate();
    };

    class FaceWorker : public QObject
    {
    Q_OBJECT

    public:
    FaceWorker(int threadID, QObject* parent = NULL);
    ~FaceWorker();

    private:

    int threadNumber;
    

    public slots:
    void doWork();

    signals:
    void resultReady(int threadID);
    };@

    Sorry for formatting.. iPad

    Thanks for ideas and help

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      Hi,

      The code looks OK. If the debug message in doWork() is printed, than handleResults() should be called. But to be sure, you can check that the connections are really made:
      @
      if ( ! connect(...) )
      {
      //Houston, we have a problem!
      }
      @

      What is the second parameter 'i' passed to the FaceWorker constructor? If i is the parent, this is not the right thing to do because you "can't":http://doc.qt.io/qt-5/qobject.html#moveToThread move an object with a parent to another thread. I don't know whether this has anything to do with your problem.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        glararan
        wrote on last edited by
        #3

        Connects were ok... I just made it another way, bit hacky but I didnt have time for solving it. Other connections were working like MainWindow, OpenGLWidget, etc.

        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