[Qt-interest] QFileDialog exec bug?

Luca Fasano lucafasano at interfree.it
Fri Jun 26 11:12:46 CEST 2009


Following a simple example showing a strange behaviour that I try to
describe (making some tests you can understand why I'm surprised):
 - if I use getOpenFileName all works fine!
 - if I use exec_():
    - if no execption raised all works fine
    - if it raises an exception:
        - If I double-click on a file, a message remains in statusBar
and QAction remain checked. But it happens *only* with action *in
toolbar*!! (opening dialog with action in QMenuBar all works fine).
Strange!!!!

Precising, only QAction in QToolbar remain checked only If I doubleclick
on a file only if an exception raised :) .
If there is a bug it should be trivial, but I can't understand in what
component it is!


import os, sys
from PyQt4 import QtGui, QtCore


class MainWin(QtGui.QMainWindow):
    def __init__(self, *args):
        super(MainWin, self).__init__(*args)

        actionFileOpen = QtGui.QAction(QtGui.QIcon(''),
                                       self.tr('&Open'), self)
        actionFileOpen.setObjectName('actionFileOpen')
        actionFileOpen.setStatusTip(self.tr('Open an existing file'))
        self.connect(actionFileOpen, QtCore.SIGNAL('triggered()'),
                     self.openFile)

        toolbar = QtGui.QToolBar(self)
        toolbar.addAction(actionFileOpen)
        self.addToolBar(toolbar)

        openmenu = self.menuBar().addMenu(self.tr('Menu'))
        openmenu.addAction(actionFileOpen)

        self.statusBar().showMessage('ready')

    def openFile(self, *args):
        filed = QtGui.QFileDialog()

        # test what happens if it's used exec_() or
getOpenFileName(self)
        filed.exec_ ()
        fileName = str(filed.selectedFiles()[0])

        # test what happens if following instruction is executed or not
        raise AttributeError('error')


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    m = MainWin()
    m.show()
    os._exit(app.exec_())






More information about the Qt-interest-old mailing list