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. Connection of signal from separate ( child ) thread to slot of mainwindow ( parent thread - main thread ) problem[SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Connection of signal from separate ( child ) thread to slot of mainwindow ( parent thread - main thread ) problem[SOLVED]

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

    Hi,

    How are you doing?

    This is a relatively simple threading problem. I have a main thread where child thread were created and run called:

    @@dcc = new DetectClassifyComputation();
    connect(dcc,SIGNAL(data_ready()),this,SLOT(plot_processed_samples()),Qt::QueuedConnection);

    ....
    dcc->updatePDParameters(this->samples_to_process,&pks,&pks_ind,this->smpl_rate,stng.getUi()->spinBox_det_ratio->value()*0.1);
    cout<<"before starting new thread "<<endl;
    dcc->setStackSize(100000);
    dcc->start(QThread::HighPriority);
    cout<<"after starting new thread "<<endl;
    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    this->setEnabled(false);
    cout<<"PREPROCESS 6. "<<endl;
    while(!dcc->isFinished())
    {
    QApplication::processEvents();
    }
    this->setEnabled(true);
    QApplication::restoreOverrideCursor();
    cout<<"END OF PREPROCESS "<<endl;@

    where dcc is the instance of the thread class. The signal is defined in the thread class as:
    @Q_SIGNALS:
    void data_ready();@
    I observe, that MainWindow where I call the run of the thread "hangs" ( "freezes") after some time ( on third or second run of the thread ) with exception code c0000005. That is on Windows 7 and the program fails.
    It seems once the slot can't be invoked.
    My question is what is the problem? How to fix that?
    Thank you in advance in any help with this issue.

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

      It is not quite clear from your explanation what happens... do you see your debug "after starting new thread"?

      I just notice one thing, with every thread that I have ever used once it is set to running I never call functions directly on that thread. I always use signal/slot approach. It is little bit dangerous to call functions from other threads directly.

      so in theory you would connect another signal/slot from dcc to a slot on "this" (main window?) telling it that it has finished doing whatever it is doing.
      Also worth checking / debugging your dcc thread that it is still running (get some printfs or somthing comming out of it to see what it is doing).

      I assume you have some code in the Thread::run() function for when it gets the start signal? - what happens then?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        swhweng
        wrote on last edited by
        #3

        Hi,
        Thank you for your try to help. Yep, I connect signal from child thread with slot from parent thread. I've fixed recently the problem, the signal-slot connection should be queued, I've left default thread stack size and the
        while(!dcc->isFinished())
        {
        QApplication::processEvents();
        }
        should not be run. So it works fine now. Closed. Thanks.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          code_fodder
          wrote on last edited by
          #4

          no problem, well done, good luck :)

          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