Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, March 2007
QT and POSIX Threads


Message 1 in thread

Hi,

I have a main program which creates two threads.

In the first thread, i have created the GUI which has a log window.

In the other thread, i m running some application, i want to redirect the 
output of the applciation (the output is continuous) to GUI log window 
which is in other thread.

I am not using QThreads and i am using pthread_create to create threads.

Can i acheive this using some QEvents? 

I thought of redirecting the output from applciation thread to Global 
Variable and i dont know how to invoke an event in the GUI thread if that 
global variable is set. 

Can anyone help me?

Best Regards,
Hemanth
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



Message 2 in thread

On Wednesday 14 March 2007 10:23, Hemanth N wrote:
> Hi,
>
> I have a main program which creates two threads.
>
> In the first thread, i have created the GUI which has a log window.

First, be sure to read 
http://doc.trolltech.com/4.2/threads.html#threads-and-qobjects, because:

"Although QObject is reentrant, the GUI classes, notably QWidget and all its 
subclasses, are not reentrant. They can only be used from the main thread. As 
noted earlier, QCoreApplication::exec() must also be called from that 
thread."

Be sure to create your GUI and call exec() in the main() thread.

> In the other thread, i m running some application, i want to redirect the
> output of the applciation (the output is continuous) to GUI log window
> which is in other thread.
>
> I am not using QThreads and i am using pthread_create to create threads.
>
> Can i acheive this using some QEvents?
>
> I thought of redirecting the output from applciation thread to Global
> Variable and i dont know how to invoke an event in the GUI thread if that
> global variable is set.

You can use QApplication::postEvent() to post events to the GUI. These events 
will be handled in the main() thread. You can put all of the data you need 
into a QEvent subclass, which also eliminates the need for global 
variables ;)

-- 
 [ signature omitted ]