Note that there are some explanatory texts on larger screens.

plurals
  1. POQt Event processing problem due to QWaitCondition
    primarykey
    data
    text
    <p>I am working on a multithread QT project. The main problem is on a serial controller class. This class uses QMutex and QWaitCondition to shyncronize write and read methods.</p> <p>The problem is about a signal blocked in a children class due to qwaitcondition wait method in the parent. Once the wait method returns, the signal in the children class is emmited (the receiver is also the children class).</p> <p>I think this method (qwaitcondition - wait) is blocking any signal emission in my entire application.</p> <p>The problem is something like that:</p> <pre><code>constructor() { anotherclass = new MyClass; } void run() { forever { if(readmethod()) waitcondition.wakeall(); } } void method1() { sendpacket(); mutex.lock(); if(waitcondition.wait(&amp;mutex,10000)) //somecode; mutex.unlock(); } class MyClass { someObject sobj; MyClass() { connect(sobj,SIGNAL(somesignal),this,SLOT(someslot)); } void someslot() { //some code } } </code></pre> <p>My slot called someslot only is called once the qwaitcondition returns due to the timeout (10 seconds in this case).</p> <p>I just want to use mutex and the qwaitcondition in this class, not in the entire application. I tried to instantiate the children class in the main thread but I got the same behavior.</p> <p><strong>CONCEPTUAL TEST</strong></p> <p>I made a test project and I published it at this link: <a href="http://inotechcorp.com/images/files/testwaitcondition.tar.gz" rel="nofollow">testwaitconditionproject</a></p> <p>the test project works in this way: A waitcondition is iniated with timeout equal to 10 seconds in the parent thread. A children thread emit a signal every 2 seconds, an internal slot must emit a signal captured by the parent. Once the parent slot is called, a flag is set to true. This flag should fire a wakeall to finish de waitcondition.</p> <p>BUT NOT, the children's internal signals only are fired after the waitcondition timeout. THIS IS MY MAIN PROBLEM, the parent waitcondition is blocking my children's signals.</p> <p><strong>EDIT:</strong></p> <p>I solved the problem in the test project, calling the method with waitcondition in another thread. It is not possible to me to replicate the issue because the asynchronous call to the method occurs in the thread 1 (via dbus). I am wondering the dbus call is emitted in the thread 1, so my events in the children class are not going to be emitted while the instance belongs to the same thread.</p> <p><strong>EDIT 2:</strong></p> <p>I solved my problem putting the pparent and the children in an intermediate class qthread. they were instantiated in the run method, and an exec call was used too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload