PDA

View Full Version : Event Processing



QbelcorT
15th April 2009, 07:25
Hi,
I had a similar issue before, but now it's more apparent.
I am sending events with QTCLASS]QCopChannel::sendEvent()[[/QTCLASS], the receiver object is not receiving these events for some period of time later. When I cause another window event, painting, mouseevent, then the events are flushed and sent.
As a test I made a QTimer object with a timeout of 0, this is suppose to timeout when the eventloop is idle, so I put a debug() statement in this slot and it is called all the time, so the receiver object is always in an idle state. However strange enough, without doing anything in the timeout slot, the QCop events are now being received by my receiver object. So, my receiver object is always idle, I though when idling the QApplication::processEvents is being called in the eventloop.
What does this mean?
thank you.

wysota
15th April 2009, 07:34
Did you check whether the problem is on sending or receiving end?

QbelcorT
15th April 2009, 08:35
I debugged the sending routine QCopChannel::send(), returns true, which means successful, and the event and channel are correct at that point.
In the receiver object I debug when I receive an event, but nothing was being received. So, the sending is doing as it should, but the event is not being processed. (rec'd).

wysota
15th April 2009, 08:46
Do you use multiple threads? Is there a chance you are starving the event loop?

QbelcorT
15th April 2009, 09:07
Yes I have mulitple threads, 3 other threads. I commented out only 2 threads, because thread 1 does the QCop sending.
With just the one thread it still exhibits this problem. In that one thread it is a blocking read call, so if there is nothing to read it blocks. I thought during blocking the other threads have a chance to run.
Is that a problem?

wysota
15th April 2009, 09:19
Do you have an event loop running in the thread receiving QCop messages? Where (in which thread and which method) did you create the QCopChannel object?

QbelcorT
15th April 2009, 10:25
Yes, at least I hope I have an event loop running. In my main this is my code..just the basics.


TestProgram test;
test.show();
splash.finish(&test);
return app.exec();


In my 'test' object I receive the QCop events. The QCopChannel object is being created in my 'test' object.


QCopChannel *myEvents = new QCopChannel(GPIO);
connect(myEvents,SIGNAL(received(const QString &, const QByteArray &)),
this, SLOT(readProcessEvents(const QString &, const QByteArray &)));



My one thread that sends the QCop events uses the QCopChannel::send() static function. Here is my sending routine.


int sendQCopEvent( char *channel, char *string, const QByteArray &data)
{
if(QCopChannel::isRegistered(channel))
{
QCopChannel::send(channel, string, data);
QCopChannel::flush();
// qDebug() << channel << string << __FUNCTION__ << endl;
return 0;
}
return -1;
}

wysota
15th April 2009, 11:03
The code looks fine. I understand the last piece of code is in a different application than previous ones?

QbelcorT
15th April 2009, 13:11
yes, sort of.
The last piece of code is a routine called by my thread. My thread is written in C code. It is all compiled into one application.

wysota
15th April 2009, 16:32
So why do you need the channel in the first place? Why not pass the data directly?

QbelcorT
15th April 2009, 23:48
Yes I realize I could pass the data directly however when I first started the design they were two separate processes. In order to ease the transition, and leave it open to keep them separate I kept the QCopChannel scheme.
My 'test' object needs to monitor the thread for events.