[Qt-interest] close app before exec()
Constantin Makshin
dinosaur-rus at users.sourceforge.net
Wed Jul 1 21:38:01 CEST 2009
Actually, exceptions are the best way to tell about an error in the
constructor. :)
On Wed, 01 Jul 2009 13:08:20 +0400, RFOG <no at mail.com> wrote:
> Or better than that: throw an exception in ctor and catch in main...
>
> I know is not a good idea fire an exception in a ctor, but if you are
> going to exit...
>
> On Wed, 01 Jul 2009 11:04:40 +0200, RFOG <no at mail.com> wrote:
>
>> Modfiy the ctor to receive a boolean by reference and the do something
>> like this:
>>
>> bool bExit;
>> MainWindow w(bExit); <--- Here I check for conditions...
>> if(!bExit)
>> {
>> w.show();
>> return a.exec();
>> }
>>
>> MainWindows ctor signature coud be:
>>
>> MainWindow(bool& bexit)
>> {
>> ...
>> }
>>
>> I do not know if it will work with QT, but seems a common scenario.
>> However you cannot bye sayng nothing to the user...
>>
>> On Wed, 01 Jul 2009 10:57:31 +0200, OS Prog <osprog at gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I have QMainWindow application. In the QMainWindow constructor I check
>>> for
>>> conditions and if they are not met I want to exit from the application.
>>> The
>>> close(), QApplication::exit(), and so on doesn't work, because they are
>>> before application.exec().
>>>
>>> In main.cpp I have
>>> ...
>>> MainWindow w; <--- Here I check for conditions...
>>>
>>> w.show();
>>>
>>> return a.exec();
>>>
>>> ...
>>>
>>> Regards,
>>> Nikolay
--
Constantin "Dinosaur" Makshin
More information about the Qt-interest-old
mailing list