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

Re: QThread::exec and Signals

Subject: Re: QThread::exec and Signals
From: Chris Burke
Date: Tue, 05 Jun 2007 13:36:03 -0400
Patrick,

I don't believe you want to execute your producer (currentTest) inside the thread of your consumer (QThread). In your main, run your thread (at this point, the thread should be spawned and waiting for signals in its event loop). Then, still in main, call currentTest->execute(). Your basic problem is putting too much code in the QThread::run method.

Patrick Feistel wrote:
Hi,
after tinking about the problem I don't know how to solve this one.
If I do an exec () in the run method it will continue all other instructions only after calling exit() or quit(). I want to send a SIGNAL from an object living in this thread everytime this object has acquired new data.

Could someone tell me a solution for this?

Regards,
Patrick

"Patrick Feistel" <Feistel@xxxxxxxxxx> schrieb im Newsbeitrag news:f43c99$rfp$1@xxxxxxxxxxxxxxxxxxxxx
Hi again,

this is correct I emit the SIGNAL in  currentTest->execute( )
But I can't put the exec after this statement, because I need a QTimer in execute

How can I solve this problem?

Regards,
Patrick

"Hemanth N" <hemanth.n@xxxxxxx> schrieb im Newsbeitrag news:OFB97A618B.627B9010-ON652572F1.0035F34E-652572F1.00364C58@xxxxxxxxxx

Hi Patrick,

Probably what i can understood from your code is:

You are emitting the signal in currentTest-> execute( )

Please look at the documents once , specifically on exec( ) functionality.

exec( ) will invoke the event handler and execution of that statement doesnt return immediately unless the main widget is closed or application is killed.
(In this case may be when the thread is killed)

Hence move the currentTest-> execute( ) onto the top of exec( )

Thanks & Regards,
Hemanth Kumar Nakkina
Tata Consultancy Services
Mailto: hemanth.n@xxxxxxx
Website: http://www.tcs.com


"Patrick Feistel" <Feistel@xxxxxxxxxx>
06/05/2007 03:10 PM Toqt-interest@xxxxxxxxxxxxx
cc
SubjectRe: QThread::exec and Signals







Hello and thanks for posting,

if I change the order of connect and exec it still won't work.

I do the following in the QThread::run():
--
...
currentTest = new TestConfigure();
connect(currentTest, SIGNAL(newData()), this, SLOT(dataAvailable()));
exec();
currentTest->execute();
exit(0);
currentTest->disconnect();
delete currentTest;
currentTest = NULL;
...
--

I don't know how to get the SIGNAL.

Regards,
Patrick


"Tomás Kazmar" <Tomash.Kazmar@xxxxxxxxx> schrieb im Newsbeitrag
news:15430.17645-1211-222591844-1181035584@xxxxxxxxxxxx
Hi Patrick,

 as I understand it, when you call QThread::exec() thread enters an event
loop
and a call to connect() is exectuted only after the thread exits the loop.
If you
change the order of these two it will start working.

Maybe also you want to read the part of the docs concerning
multithreading,
especially:

http://doc.trolltech.com/4.3/threads.html#per-thread-event-loop

and

http://doc.trolltech.com/4.3/threads.html#signals-and-slots-across-threads


Regards,
Tomas


# Hello,
#
# I have an app with 2 threads.
# In QThread::run I first call QThread::exec() and than I connect a SIGNAL
of
# OBJECT_A to the SLOT of my class derived from QThread. After that I call
a
# function of OBJECT_A which emits the SIGNAL.
# My problem is that the SIGNAL is not received by the class derived from
# QThread.
#
# Can you tell me how to do such things with an event-loop.
#
# Regards,
# Patrick
#
# P.S.: I need a seperate event-loop to use QTimer in my second thread...

--
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/
--
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/

ForwardSourceID:NT000114D6

=====-----=====-----=====
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



--
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/
--
chris burke
phone: 617-621-0060 x195
email: cburke@xxxxxxx
skype: chris.burke0

--
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>