Seg fault testing for Qt::app

"Potts, Alistair" <[email protected]> Mon, 13 Jun 2005 14:39:35 +1200
Newsgroups gmane.comp.kde.devel.perl
Message-ID <[email protected]>
Hello,
I'm having a little trouble with detecting whether or not a Qt::Application
object has already been created. I've tried the obvious:

my $application = Qt::Application() unless Qt::app();

but this causes a segmentation fault. The problem seems to be that the call
to Qt::app() tries to create a new reference from the sv_qapp pointer, even
though it has never been initialised by a call to Qt::Application(). Is
there a better way, or should this work?
If I'm not missing something obvious about why this should be, this little
patch to PerlQt/Qt.xs seems to fix it.

Cheers,
Alistair

--- Qt.xs.org   2003-09-18 23:46:33.000000000 +0000
+++ Qt.xs       2005-06-13 14:23:20.000000000 +0000
@@ -2175,7 +2175,10 @@
 SV *
 app()
     CODE:
-    RETVAL = newRV_inc(sv_qapp);
+    if(sv_qapp == 0)
+        RETVAL = &PL_sv_undef;
+    else
+        RETVAL = newRV_inc(sv_qapp);
     OUTPUT:
     RETVAL

This communication is confidential and may contain privileged material.
If you are not the intended recipient you must not use, disclose, copy or retain it.
If you have received it in error please immediately notify me by return email
and delete the emails.
Thank you.