[Qt-interest] signal and slot

Andre Somers andre at familiesomers.nl
Tue Mar 2 10:46:15 CET 2010


yanqzhi at gmail.com wrote:
> I am sorry to answer to you directly.
>
> class A
> {
> ......
> signals:
> void signal1();
> void signal2();
>
> public:
> void function()
> {
> B *b = new B();
>
> connect(this, SIGNAL( signal1() ) ), b, SLOT( slot1() ) );
> connect(this, SIGNAL( signal2() ) ), b, SLOT( slot2() ) );
>
> emit signal1();
> emit signal2();
> }
> }
>
> class B
> {
> ........
> public slots:
> void slot1()
> {
> //read database;
> }
>
> void slot2()
> {
> //show data read by slot1;
> }
>
> public:
> void function1()
> {
> slot1();
> }
> }
>
> When the funtion in the class A executes, the siganl1 and signal2 will
> be emitted.
> I want that signal2 will be emitted until the excution of slot1 finish.
> if use your method when function1 in the class B excutes, the slot2 in
> class will excutes;
That is what happens if the connections are direct
(Qt::DirectConnection), which is also the case if the objects live in
the same thread and you use the automatic connection mode. Are you
actually running into a problem, or is this a theoretical issue?

Note that you do not have control over the order in which the connected
slots to a single signal are executed! If you want that, you need to
emit different signals, like eventFase1(), eventFase2().
>
> I want to know there is a funtion or some method like SendMessage in
> MFC which sends a message
> and waits until the message has been processed;
Sure there is. Call a method directly, call it through a
direct-connected signal/slot method, use a Qt::BlockingQueuedConnection
or even use QCoreApplication::sendEvent().

André





More information about the Qt-interest-old mailing list