[PyQt] fixes for scribble issues

Hans-Peter Jansen hpj at urpla.net
Mon Nov 29 14:59:35 GMT 2010


Dear Phil,

examples/widgets/scribble.py suffers from a couple of issues at the 
moment. Most importantly, QtGui.QImageWriter.supportedImageFormats() 
and QAction.data() return QByteArrays now (with QVariant API 2), 
resulting in:

Traceback (most recent call last):
  File "./scribble.py", line 317, in <module>
    window = MainWindow()
  File "./scribble.py", line 178, in __init__
    self.createActions()
  File "./scribble.py", line 236, in createActions
    action = QtGui.QAction(text, self, triggered=self.save)
TypeError: arguments did not match any overloaded call:
  QAction(QObject): argument 1 has unexpected type 'QByteArray'
  QAction(QString, QObject): argument 1 has unexpected type 'QByteArray'
  QAction(QIcon, QString, QObject): argument 1 has unexpected type 'QByteArray'

on start up and

Traceback (most recent call last):
  File "./scribble.py", line 200, in save
    self.saveFile(fileFormat)
  File "./scribble.py", line 304, in saveFile
    "%s Files (*.%s);;All Files (*)" % (fileFormat.upper(), fileFormat))
AttributeError: 'QByteArray' object has no attribute 'upper'

Further more, printing (to PDF at least) leads to:

QPaintDevice: Cannot destroy paint device that is being painted
Speicherzugriffsfehler

(gdb) set args ./scribble.py
(gdb) run
Starting program: /usr/bin/python ./scribble.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb52c3b90 (LWP 29758)]
[New Thread 0xb48ffb90 (LWP 29759)]
QPaintDevice: Cannot destroy paint device that is being painted
[Thread 0xb52c3b90 (LWP 29758) exited]
[Thread 0xb48ffb90 (LWP 29759) exited]

Program received signal SIGSEGV, Segmentation fault.
0x00000002 in ?? ()
(gdb) bt
#0  0x00000002 in ?? ()
#1  0xb643b668 in ~QPainter (this=0x83dce70) at painting/qpainter.cpp:1504
#2  0xb6fe4010 in release_QPainter (sipCppV=0x83dce70) at QtGui/sipQtGuiQPainter.cpp:5596
#3  0xb6fe406c in dealloc_QPainter (sipSelf=0xb5b9a454) at QtGui/sipQtGuiQPainter.cpp:5607
#4  0xb7fc4f1f in forgetObject (sw=0xb5b9a454) at siplib.c:10001
#5  0xb7fc4fb1 in sipSimpleWrapper_dealloc (self=0xb5b9a454) at siplib.c:9230
#6  0xb7ebb68d in subtype_dealloc (self=0xb5b9a454) at Objects/typeobject.c:1018
#7  0xb7e8d24a in frame_dealloc (f=0x83b355c) at Objects/frameobject.c:417
#8  0xb7ef9bec in PyEval_EvalCodeEx (co=0xb7c39410, globals=0xb7c7702c, locals=0x0, args=0xb5ee73b8, argcount=1, 
    kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2953
#9  0xb7e8ea29 in function_call (func=0xb5ebce64, arg=0xb5ee73ac, kw=0x0) at Objects/funcobject.c:524
#10 0xb7e69c1c in PyObject_Call (func=0xb5ebce64, arg=0xb5ee73ac, kw=0x0) at Objects/abstract.c:2487
#11 0xb7e779fe in instancemethod_call (func=0xb5ebce64, arg=0xb5ee73ac, kw=0x0) at Objects/classobject.c:2579
#12 0xb7e69c1c in PyObject_Call (func=0xb7c276e4, arg=0xb7c5302c, kw=0x0) at Objects/abstract.c:2487
#13 0xb7ef277f in PyEval_CallObjectWithKeywords (func=0xb7c276e4, arg=0xb7c5302c, kw=0x0) at Python/ceval.c:3548
#14 0xb7fcf19f in sip_api_invoke_slot (slot=0x81eed8c, sigargs=0xb5ee71ec) at qtlib.c:203
#15 0xb78f2e8d in PyQtProxy::invokeSlot (slot=@0x81eed8c, qargs=0xbfffd4f0) at qpycore_pyqtproxy.cpp:474
#16 0xb78f2f98 in PyQtProxy::unislot (this=0x81eed70, qargs=0xbfffd4ec) at qpycore_pyqtproxy.cpp:416
#17 0xb78f30d7 in PyQtProxy::qt_metacall (this=0x81eed70, _c=QMetaObject::InvokeMetaMethod, _id=1, _a=0xbfffd4ec)
    at qpycore_pyqtproxy.cpp:380
#18 0xb7614215 in QMetaObject::metacall (object=0x0, cl=QMetaObject::InvokeMetaMethod, idx=5, argv=0xbfffd4ec)
    at kernel/qmetaobject.cpp:237
#19 0xb7626e93 in QMetaObject::activate (sender=0x81eec90, m=0xb6c38858, local_signal_index=1, argv=0xbfffd4ec)
    at kernel/qobject.cpp:3272
#20 0xb62bad89 in QAction::triggered (this=0x81eec90, _t1=false) at .moc/release-shared/moc_qaction.cpp:263
#21 0xb62bc69f in QAction::activate (this=0x81eec90, event=QAction::Trigger) at kernel/qaction.cpp:1257
#22 0xb6786c57 in QMenuPrivate::activateCausedStack (this=0x81f1668, causedStack=@0xbfffd5c8, action=0x81eec90, 
    action_e=QAction::Trigger, self=true) at widgets/qmenu.cpp:993
#23 0xb678cbbb in QMenuPrivate::activateAction (this=0x81f1668, action=0x81eec90, action_e=QAction::Trigger, 
    self=<value optimized out>) at widgets/qmenu.cpp:1085

Explicitely end()ing the painter in print_ solved this.

While at it, add some obviously missing "self" references to size().

Pete
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scribble.diff
Type: text/x-diff
Size: 2189 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20101129/01e2091a/attachment.diff>


More information about the PyQt mailing list