[Interest] post event between threads

Riccardo Roasio riccardo.roasio at gmail.com
Tue Apr 3 11:19:18 CEST 2012


Ok,

here serial rx threaad emit the signal:

emit MessageReceivedSignal();

here the main thread catch the signal:

connect(rxRoutine, SIGNAL(MessageReceivedSignal()),this,
SLOT(TestSlot()),Qt::QueuedConnection);

here is the constructor of scriptrunner that should catch the signal
but it doesn't

ScriptRunner::ScriptRunner(QObject *parent,Configuration *c,Script
*s,TxRoutine *t,RxRoutine *r,ComunicationLogConfigList *l,Message1281*
m) :
    QThread(parent)
{
    message1281=m;
    comunicationLog=l;
    activeConfiguration=c;
    txRoutine=t;
    rxRoutine=r;
    myScript=s;
    exit=false;

    currentStep=0;

    connect(rxRoutine, SIGNAL(MessageReceivedSignal()),this,
SLOT(TestSlot()),Qt::QueuedConnection);
}

and here is when i create the thread scriptrunner:

 qDebug()<<"going to start... "<<tmpScript->GetName();
                tmpRunner=new
ScriptRunner(0,activeConfiguration,tmpScript,txRoutine,rxRoutine,comunicationLog,message1281);
                tmpScript->SetRunning(true);
                tmpRunner->start();
                runners.append(tmpRunner);


Il 03 aprile 2012 11:12, Samuel Gaist <samuel.gaist at edeltech.ch> ha scritto:
> If you show us the code you use to setup the connections, we might be able to offer better help.
>
> Samuel
>
> On 3 avr. 2012, at 11:09, Riccardo Roasio wrote:
>
>> I'm trying using signal/slots with Qt::QueuedConnection.
>> Now the problem is this one..i have
>>
>> - gui thread (main)
>>
>> - serial rx thread
>>
>> - scriptmanager thread
>>        |
>>        |----- script runner 1 thread (started from scriptsmanager)
>>        |
>>        |----- script runner 2 thread (started from scriptsmanager)
>>        |
>>        |----- script runner N thread (started from scriptsmanager)
>>
>> now the event is emitted from serial rx thread
>>
>> the main thread is able to catch the signal
>> the scriptmanager is able to catch the signal
>> the scriptrunner is NOT able to catch the signal
>>
>> the only difference is that the sciptrunner has no parent (in the
>> construtor the parent is NULL)
>>
>> Riccardo
>>
>>
>>
>>
>> Il 03 aprile 2012 09:29, Riccardo Roasio <riccardo.roasio at gmail.com> ha scritto:
>>> Ok,
>>>
>>> i will try!
>>>
>>> thanks everybody
>>>
>>> Il 03 aprile 2012 09:19, Lincoln Ramsay <lincoln.ramsay at nokia.com> ha scritto:
>>>> On 04/03/2012 05:07 PM, ext Riccardo Roasio wrote:
>>>>> I cannot use signal/slot because is blocking and i need to continue
>>>>> reading from serial port while message is processing...
>>>>
>>>> If you emit a signal and the receiver lives on the current thread and
>>>> the connect() call did not use Qt::QueuedConnection, then it is
>>>> "blocking". If you use Qt::DirectConnection or
>>>> Qt::BlockingQueuedConnection then it is always "blocking".
>>>>
>>>> But if the receiver lives on another thread or if you specified
>>>> Qt::QueuedConnection then the signal puts an object on the event loop
>>>> and returns immediately.
>>>>
>>>> --
>>>> Lincoln Ramsay - Senior Software Engineer
>>>> Qt Development Frameworks, Nokia - http://qt.nokia.com/
>>>> _______________________________________________
>>>> Interest mailing list
>>>> Interest at qt-project.org
>>>> http://lists.qt-project.org/mailman/listinfo/interest
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list