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

Qt-interest Archive, February 2008
QCoreApplication won't quit


Message 1 in thread

Hello !

My little QCoreApplication won't quit if quit() or exit(0) is called. 
(tried it with 4.3.3 and 4.4-beta1)

Does anyone has also this problem ?

here is some sample code, is there something wrong ?

#include <QtCore>
#include "myclass.h"

int main(int argc, char *argv[])
{
    QCoreApplication qapp(argc, argv);
     MyClass *class = new MyClass(0);
    QObject::connect( class, SIGNAL( done() ), &qapp, SLOT( quit() ) );
    class->doSomething();  // Emits done, when finished
    return qapp.exec();
}

Thanks a lot for any help !

Best regards,

Heiko

-- 
 [ signature omitted ] 
begin:vcard
fn:Heiko Steindl
n:Steindl;Heiko
org:Computerhaus EDV-Handels Ges.m.b.H
adr;quoted-printable:;;Wienerstrasse 35a;Kapfenberg;Steiermark;8605;=C3=96sterreich
email;internet:heiko@xxxxxx
tel;work:+43 (0)3862 27777
tel;fax:+43 (0)3862 27777 77
tel;cell:+43 (0)676 3727777
x-mozilla-html:TRUE
url:http://www.kom.at
version:2.1
end:vcard


Message 2 in thread

On Thu, Feb 28, 2008 at 02:23:11PM +0100, Heiko Steindl wrote:
> Hello !
> 
> My little QCoreApplication won't quit if quit() or exit(0) is called. 
> (tried it with 4.3.3 and 4.4-beta1)
> 
> Does anyone has also this problem ?
> 
> here is some sample code, is there something wrong ?
> 
> #include <QtCore>
> #include "myclass.h"
> 

do you have the Q_OBJECT macro in MyClass?

regards,

Andre

--
 [ signature omitted ] 

Message 3 in thread

If doSomething() is a normal function (that is to say it doesn't perform
asynchronous operations) it must terminate before app.exec() is actually
executed: thus, the signal done() should be emitted before the main event
loop is entered.
Is my interpretation right? May a signal be emitted outside the event loop?
(I haven't ever try it...although i suppose it is possible)

Message 4 in thread

yes, Q_OBJECT Macro is present.

Yes it is possible, that the signal is emitted before but, also this 
won't work:

#include <QtCore>
#include "myclass.h"

int main(int argc, char *argv[])
{
   QCoreApplication qapp(argc, argv);

    QCoreApplication::quit();
   return qapp.exec();
}

Manuel Fiorelli schrieb:
> If doSomething() is a normal function (that is to say it doesn't 
> perform asynchronous operations) it must terminate before app.exec() 
> is actually executed: thus, the signal done() should be emitted before 
> the main event loop is entered.
> Is my interpretation right? May a signal be emitted outside the event 
> loop? (I haven't ever try it...although i suppose it is possible)
>

-- 
 [ signature omitted ] 
begin:vcard
fn:Heiko Steindl
n:Steindl;Heiko
org:Computerhaus EDV-Handels Ges.m.b.H
adr;quoted-printable:;;Wienerstrasse 35a;Kapfenberg;Steiermark;8605;=C3=96sterreich
email;internet:heiko@xxxxxx
tel;work:+43 (0)3862 27777
tel;fax:+43 (0)3862 27777 77
tel;cell:+43 (0)676 3727777
x-mozilla-html:TRUE
url:http://www.kom.at
version:2.1
end:vcard


Message 5 in thread

Yeah but that is a fairly obvious mistake. You are executing after calling quit.

2008/2/28, Heiko Steindl <heiko@xxxxxx>:
> yes, Q_OBJECT Macro is present.
>
>  Yes it is possible, that the signal is emitted before but, also this
>  won't work:
>
>
>  #include <QtCore>
>  #include "myclass.h"
>
>
> int main(int argc, char *argv[])
>  {
>    QCoreApplication qapp(argc, argv);
>
>
>     QCoreApplication::quit();
>    return qapp.exec();
>  }
>
>  Manuel Fiorelli schrieb:
>
> > If doSomething() is a normal function (that is to say it doesn't
>  > perform asynchronous operations) it must terminate before app.exec()
>  > is actually executed: thus, the signal done() should be emitted before
>  > the main event loop is entered.
>  > Is my interpretation right? May a signal be emitted outside the event
>  > loop? (I haven't ever try it...although i suppose it is possible)
>  >
>
>
> --
>
>
>  Mit freundlichen Grüßen
>
>  Heiko Steindl
>
>
>
>

--
 [ signature omitted ] 

Message 6 in thread

ok, but how can I make this correct, so then quit is called after the 
signal is emitted ?

Thomas Dähling schrieb:
> Yeah but that is a fairly obvious mistake. You are executing after calling quit.
>
> 2008/2/28, Heiko Steindl <heiko@xxxxxx>:
>   
>> yes, Q_OBJECT Macro is present.
>>
>>  Yes it is possible, that the signal is emitted before but, also this
>>  won't work:
>>
>>
>>  #include <QtCore>
>>  #include "myclass.h"
>>
>>
>> int main(int argc, char *argv[])
>>  {
>>    QCoreApplication qapp(argc, argv);
>>
>>
>>     QCoreApplication::quit();
>>    return qapp.exec();
>>  }
>>
>>  Manuel Fiorelli schrieb:
>>
>>     
>>> If doSomething() is a normal function (that is to say it doesn't
>>>       
>>  > perform asynchronous operations) it must terminate before app.exec()
>>  > is actually executed: thus, the signal done() should be emitted before
>>  > the main event loop is entered.
>>  > Is my interpretation right? May a signal be emitted outside the event
>>  > loop? (I haven't ever try it...although i suppose it is possible)
>>  >
>>
>>
>> --
>>
>>
>>  Mit freundlichen Grüßen
>>
>>  Heiko Steindl
>>
>>
>>
>>
>>     
>
> --
> 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/
>
>
>   

-- 
 [ signature omitted ] 
begin:vcard
fn:Heiko Steindl
n:Steindl;Heiko
org:Computerhaus EDV-Handels Ges.m.b.H
adr;quoted-printable:;;Wienerstrasse 35a;Kapfenberg;Steiermark;8605;=C3=96sterreich
email;internet:heiko@xxxxxx
tel;work:+43 (0)3862 27777
tel;fax:+43 (0)3862 27777 77
tel;cell:+43 (0)676 3727777
x-mozilla-html:TRUE
url:http://www.kom.at
version:2.1
end:vcard


Message 7 in thread

As far as I understand the Qt Event handling, quit() is called after the
signal is emitted, but when you emit it, exec isn't yet executed, thus
quit() has no effect.

Message 8 in thread

So it seems, that I'm standing on a line :)

If I moved the part with connect( ... qapp, SLOT (quit) ) after 
qapp.exec() it also don't quit the application.

thanks a lot !

Manuel Fiorelli schrieb:
> As far as I understand the Qt Event handling, quit() is called after 
> the signal is emitted, but when you emit it, exec isn't yet executed, 
> thus quit() has no effect.

-- 
 [ signature omitted ] 
begin:vcard
fn:Heiko Steindl
n:Steindl;Heiko
org:Computerhaus EDV-Handels Ges.m.b.H
adr;quoted-printable:;;Wienerstrasse 35a;Kapfenberg;Steiermark;8605;=C3=96sterreich
email;internet:heiko@xxxxxx
tel;work:+43 (0)3862 27777
tel;fax:+43 (0)3862 27777 77
tel;cell:+43 (0)676 3727777
x-mozilla-html:TRUE
url:http://www.kom.at
version:2.1
end:vcard


Message 9 in thread

On Thursday 28 February 2008 17:36:05 Heiko Steindl wrote:

int main(int argc, char *argv[])
{
    QCoreApplication qapp(argc, argv);
    MyClass *class = new MyClass(0);
    QObject::connect( class, SIGNAL( done() ), &qapp, SLOT( quit() ) );
    QTimer::singleShot(0, class, SLOT(doSomethingSlot()))
    return qapp.exec();
}

this way your code would be executed from inside the event loop.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 10 in thread

Thanks a lot ! you saved my day !

this works perfectly ! ;-)

Vladimir Pouzanov schrieb:
> On Thursday 28 February 2008 17:36:05 Heiko Steindl wrote:
>
> int main(int argc, char *argv[])
> {
>     QCoreApplication qapp(argc, argv);
>     MyClass *class = new MyClass(0);
>     QObject::connect( class, SIGNAL( done() ), &qapp, SLOT( quit() ) );
>     QTimer::singleShot(0, class, SLOT(doSomethingSlot()))
>     return qapp.exec();
> }
>
> this way your code would be executed from inside the event loop.
>
>   

-- 
 [ signature omitted ] 
begin:vcard
fn:Heiko Steindl
n:Steindl;Heiko
org:Computerhaus EDV-Handels Ges.m.b.H
adr;quoted-printable:;;Wienerstrasse 35a;Kapfenberg;Steiermark;8605;=C3=96sterreich
email;internet:heiko@xxxxxx
tel;work:+43 (0)3862 27777
tel;fax:+43 (0)3862 27777 77
tel;cell:+43 (0)676 3727777
x-mozilla-html:TRUE
url:http://www.kom.at
version:2.1
end:vcard


Message 11 in thread

	 Heiko Steindl writes

> My little QCoreApplication won't quit if quit() or exit(0) is called. 

> (tried it with 4.3.3 and 4.4-beta1)
> 
> Does anyone has also this problem ?
> 
> here is some sample code, is there something wrong ?
> 
> #include <QtCore>
> #include "myclass.h"
> 
> int main(int argc, char *argv[])
> {
>     QCoreApplication qapp(argc, argv);
>      MyClass *class = new MyClass(0);
>     QObject::connect( class, SIGNAL( done() ), &qapp, SLOT( quit() ) 
);
>     class->doSomething();  // Emits done, when finished
>     return qapp.exec();
> }

You just need to add Qt::QueuedConnection as an additional argument to 
the connect() call.
http://doc.trolltech.com/4.3/qt.html#ConnectionType-enum

Regards,

-- 
 [ signature omitted ]