qt-interest@trolltech.com
[Top] [All Lists]

Pass Events to Thread in Console App?

Subject: Pass Events to Thread in Console App?
From: Joshua Senecal
Date: Wed, 30 Jul 2008 15:10:26 -0700
Hi All,

I have a console application (QCoreApplication) I'm writing that is 
event-driven. The app (I'll call it the "Controller") creates an 
instance of a controller thread that does pretty much all the work in 
the application, starts the thread, and then enters it's event loop 
(app.exec()).

The thread creates a QTcpServer instance and enters its event loop 
(QThread::exec()). Signals are used to wake the thread to establish 
connections, and accept periodic status updates delivered over the 
sockets. At regular intervals these status updates are packaged and sent 
to another application, over another socket. In essence, this thread 
(and application) is like a post office, with some intelligence.

I need to add a console command-line interface (CLI) to the Controller 
application, to display status and also to inject status updates for 
debugging purposes. One possibility is to create the interface as a 
separate app that connects to the controller like any other app, and add 
functionality to the controller thread so that if the CLI app is 
connected all traffic is duplicated and sent to the CLI.

I'm also looking into the possibility of adding the CLI to the 
controller thread directly. Ideally I'd like a keypress to trigger an 
event that would be handled in the thread (i.e. keypresses would be 
collected and appended to form command strings). The problem is that the 
application and thread each have their own event loops, and it appears 
that events are being sent to the application, and are not passed to the 
thread.

So, how do I pass events to the thread? Filters apparently will not 
work, because event filters require the two objects to be in the same 
thread.

Or is there a better way to do this? Any suggestions would be 
appreciated.

Thanks very much!

-Josh Senecal

--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>