On Wed, Dec 22, 2010 at 1:34 PM, Matti Airas <[email protected]> wrote:
> On 21.12.2010 22:25, ext Thomas Perl wrote:
>
>> Another situation where that happens is when you construct a
>> QApplication without $DISPLAY set:
>>
>> $ export DISPLAY=
>> $ python
>> Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
>> [GCC 4.4.5] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>>
>>>>> from PySide.QtGui import QApplication
>>>>> app = QApplication([])
>>
>> PySideApp: cannot connect to X server
>> $ echo $?
>> 1
>>
>> In this case, I think it would be good to have an exception at the
>> Python level, as this error is something that only happens when
>> $DISPLAY is not set, so catching the exception and dealing with it
>> (i.e. by printing a nice error message like "You do not have $DISPLAY
>> set.") makes more sense. Should I turn this into a bug/feature
>> request?
>
> Again, in my opinion, the guideline should be that we should try to catch
> the C++ errors whenever we can and cast Python exceptions for them. Of
> course, in many cases this might not be feasible due to performance or
> implementation issues, so reason must prevail. :-)
>
> In this specific case, I agree that it would be nice to catch the error if
> it's possible, so go ahead and file a bug if you feel like it.
>
> Cheers,
>
> ma.
> _______________________________________________
> PySide mailing list
> [email protected]
> http://lists.openbossa.org/listinfo/pyside
>

May be Qt should raise exception instead of handling error situation?

This is the code that generated error string and exits application
(http://qt.gitorious.org/qt/qt/blobs/529b30b96435491fc6994515862f44d24efc754f/src/gui/kernel/qwidget.cpp#line217):

    if (!qApp) {
        qFatal("QWidget: Must construct a QApplication before a QPaintDevice");
        return;
    }

Documentation for qFatal() says
(http://doc.qt.nokia.com/latest/qtglobal.html#qFatal) that it prints
error message and then

> If you are using the default message handler this function will abort on Unix 
> systems to create a core dump. On Windows, for debug builds, this function 
> will report a _CRT_ERROR enabling you to connect a debugger to the 
> application.

And:

> To suppress the output at runtime, install your own message handler with 
> qInstallMsgHandler().

If I correctly understand we can install our own error message handler
that will raise exception instead of terminating application.
If this method will work we will be able to handle all internal Qt
errors (because they all should use functions qFatal(), qWarning(),
etc)

What do you, list readers, think about this?

--
Vladimir Rutsky
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to