[Qt-interest] QFileDialog exec bug?

Andreas Pakulat apaku at gmx.de
Fri Jun 26 11:49:45 CEST 2009


On 26.06.09 11:12:46, Luca Fasano wrote:
> 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!

So this only happens when the exception is raised in openFile? Why don't
you handle the exception? As far as I can see the bug is in your code
because you don't handle exceptions. 

In C++ Qt apps you're forced to handle all C++ exceptions before they can
reach Qt's event loop, else Qt will simply exit the application. I think
the same holds true for PyQt and python exceptions. You must not let any
exception out of a function that can be called (directly or indirectly)
from the Qt event loop. In your case, the mouse-click event is triggering
the actions' triggered() signal, which directly calls your slot. And hence
the exception goes back into the Qt event loop and causes the internal
state of the QAction to break.

Andreas

-- 
You will be married within a year, and divorced within two.



More information about the Qt-interest-old mailing list