[PyQt] Segmentation fault doing QMenu.exec_() on Mac OS X

Davide Guidi davide.guidi at gmail.com
Thu Jul 2 11:50:57 BST 2009


Hello list,

I have a kind of weird problem when running QMenu.exec_().
If I run it in the dropEvent() of a widget in a QDockWidget, I receive  
segmentation fault.
This happens with PyQt 4.5.1 and with PyQt-trunk (compiled against  
Qt4.5.1 and Qt4.5.2 respectively) on Mac Os X.
The same code runs properly on the Windows platform. The bug does not  
seems to appear if I do the same operation on widgets not hosted in  
QDockWidget.

An example code is provided below: When I drop the left widget onto  
the right one and I select the 'Surprise' action, I receive segfault.

Am I missing something obvious?

Thanks for the help,
Davide


from PyQt4 import QtCore, QtGui
import sys

class Label(QtGui.QLabel):
     def __init__(self, name):
         super(Label, self).__init__(name)
         self.setAcceptDrops(True)

     def dropEvent(self, event):
         print 'drop'
         menu = QtGui.QMenu()
         a = QtGui.QAction(self)
         a.setText('Surprise')
         menu.addAction(a)
         menu.exec_(self.mapToGlobal(event.pos()))

     def dragEnterEvent(self, event):
         print 'accept'
         event.accept()

     def mouseMoveEvent(self, event):
         print 'drag'
         drag = QtGui.QDrag(self)
         mimeData = QtCore.QMimeData()
         drag.setMimeData(mimeData)
         drag.exec_(QtCore.Qt.CopyAction | QtCore.Qt.MoveAction)


if __name__ == '__main__':
     app = QtGui.QApplication(sys.argv)
     window = QtGui.QMainWindow()
     lt = QtGui.QDockWidget()
     lt.setWidget(Label('Drag me'))
     window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, lt)
     rt = QtGui.QDockWidget()
     rt.setWidget(Label('Here'))
     window.addDockWidget(QtCore.Qt.RightDockWidgetArea, rt)
     window.show()
     window.raise_()
     sys.exit(app.exec_())




More information about the PyQt mailing list