0

I have a bit complex structure of my application.

First_Main_Window(QtWidgets.QMainWindow) calls ---> Second_Main_Window(QtWidgets.QMainWindow) calls ---> Third_Window = slides_form (QtWidgets.QDialog)

It means in First Window I have list of workers, in second window - data of some worker (Phone, address) in third window - standard stages of work (i.e. photos) the worker does..

The 'First_Main_Window' opens Second_Main_Window, using this function:

def OpenWindowCurrentWorker(self):
    self.pasportdataWin = pasportdata.pasportdata_form(self)
    self.pasportdataWin.closed.connect(self.show)
    self.pasportdataWin.move(0,0)
    self.hide()
    self.pasportdataWin.show()

The Second_Main_Window opens Third_Window, using this function:

def OpenSlidesWindowForm(self):
    self.SlidesWin=slides.slides_form(self)
    self.SlidesWin.move(0,0)
    self.SlidesWin.closed.connect(self.show)
    self.hide()
    self.SlidesWin.show()


from PyQt5 import QtCore, QtWidgets, QtGui
class slides_form (QtWidgets.QDialog):
    closed = QtCore.pyqtSignal()
    def __init__(self,parent=None):
        super(slides_form, self).__init__(parent)
        self.ui = slidesUiForm.Ui_Form()
        self.ui.setupUi(self)
        self.Parent=parent
        self.ui.pushButton.clicked.connect(self.openNewSlideFile)

    @QtCore.pyqtSlot()
    def openNewSlideFile (self):
        Slideflnames = QtWidgets.QFileDialog.getOpenFileNames(self, "Open Image file", "All images(*.png *.gif *.jpg *jpeg *.bmp *.tiff   .tif)")[0]
        for ii in range(len(Slideflnames)):
               ........
            shutil.copy(os.path.abspath(Slideflnames[ii]), NEWPATH)

The problem is that I decided to move from PyQt4, where all worked fine, to PyQt5. And the problem is that after calling procedure "openNewSlideFile" application closes without any warnings.

Any call to QtWidgets.QFileDialog.getOpenFileNames from the second and third windows finishes the application. I tried to use "None" instead of "self" in parent position, but it didn't help.

Please help me, I'm not very strong programmer and don't understand this problem, especially when all works on PyQt4.

I have PyQt 5,9 as I could uderstand: Here is information about PyQt5 from Synaptics

Here is the console output, using pure python3 and python3 -m pdb

When I start it via Python3 - it finishes with no errors shown

When I start it via python3 - m pdb - it finished with segmentation error

[alex@comp projects_PyQt5]$ python3
Python 3.5.1 (default, May  5 2016, 10:50:17) 
[GCC 5.3.1 20151207 (ALT Linux 5.3.1-alt3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
[1]+  Stopped                 python3
[alex@comp projects_PyQt5]$ python3 BaseCenter.py
[alex@comp projects_PyQt5]$ python3 -m pdb BaseCenter.py
> /home/alex/projects_PyQt5/BaseCenter.py(3)<module>()
-> import os
(Pdb) continue
QXcbConnection: XCB error: 3 (BadWindow), sequence: 2466, resource id: 39846744, major code: 40 (TranslateCoords), minor code: 0
The program exited via sys.exit(). Exit status: 0
> /home/alex/projects_PyQt5/BaseCenter.py(3)<module>()
-> import os
(Pdb) continue
Segmentation error
[alex@comp projects_PyQt5]$

I found some kind of answer to my question - in my case every opened "child" window hides previous "parent window" when initialized and shows "parent" back when closes - in order to minimize quantity of widgets in status string of desktop

If I remove self.hide() when I call for "second window" all works fine! But! I have two windows tabs in status string (I forget english word to describe it exactly :) ) One window is inactive because active window is modal... But It looks like some unnecessary garbage and annoying me :))

aL_eX
  • 1,453
  • 2
  • 15
  • 30
  • Does the application exit cleanly or crash? Any errors from the console? – JensV Jan 20 '18 at 14:30
  • System - Linux Sometimes without any errors. sometimes - QXcbConnection: XCB error: 3 (BadWindow), sequence: 2131, resource id: 39850570, major code: 40 (TranslateCoords), minor code: 0 – Александр Jan 20 '18 at 14:44
  • I execute script via KDevelop IDE and after my script has crashed it writes: Executing python3 /home/alex/projects_PyQt5/My_App.py QXcbConnection: XCB error: 3 (BadWindow), sequence: 2438, resource id: 39850616, major code: 40 (TranslateCoords), minor code: 0 *** Normal finishing *** And I have to emphasize, that my function "openNewSlideFile" works till it's end and crash appears at the moment of exiting this function at its end, or when I write command "return" just after callig for QtWidgets.QFileDialog.getOpenFileName(s) – Александр Jan 20 '18 at 15:33
  • I think the answer is somewhere in new style of Inheritance in PyQt5, but I cannot find out the tip of tail of it because of my too low qualification... – Александр Jan 20 '18 at 15:58
  • @Александр. Please run the script in a normal console (not an IDE), then copy the whole output and put it in your question (not in a comment). Also state the exact version of python, qt and pyqt you are using. It would also help if you provided a small, self-contained test script that reproduces the problem. For me, the code in `openNewSlideFile` does not produce any errors (I just printed the file-names). – ekhumoro Jan 20 '18 at 19:04
  • @ekhumoro I tryed to provide all the information you asked for. – Александр Jan 21 '18 at 06:03
  • @Александр. So, as I suspected, there is no real problem with the code itself. It runs fine when it's executed as a stand-alone script. It's only when you run it in an IDE/debugger that the problem appears. The "BadWindow" error is comming from the X11 window manager, and is trivial - it should not stop the normal running of the code. I suggest you use an IDE/debugger that knows how to deal will such trivial errors gracefully. – ekhumoro Jan 21 '18 at 18:12
  • @ekhumoro No No :) It shows that it finished in right way - BUT this finishing is not normal finishing - because it take place in the middle of the script. I found some kind of answer to my question - in my case every opened "child" window hides previous "parent window" when initialized and shows "parent" back when closes. If I remove self.hide() when I call for "second window" all works fine! But! I have two windows tabs in status string (I forget english word to describe it exactly :) ) One window is inactive because active window is modal... – Александр Jan 21 '18 at 18:30
  • And it worked good in PyQt4... – Александр Jan 21 '18 at 18:32
  • @Александр. I still don't believe there is any real problem with the code itself. It looks like a problem caused by your specific system setup. You probably have a buggy plugin installed somewhere. Try using the `DontUseNativeDialog` option with [getOpenFileNames](https://doc.qt.io/qt-5/qfiledialog.html#getOpenFileNames). – ekhumoro Jan 21 '18 at 18:50
  • @ekhumoro I used "DontUseNativeDialog" - it didn't change anything. When I removed self.hide() when called for new window - problem disapeared. Crash looked like when procedure, containing call for "filedialog" finished, it forced application to call sys.exit(0).... I don't know how to describe more thoroughly... but the same script worked well in PyQt4. As to plugins - probably... I don't know... Now I stopped problem by removing hiding of parent window, will work further, may be wait for new PyQt version in my repositorium. – Александр Jan 21 '18 at 20:09

1 Answers1

0

I was encountering similar behavior on linux with the app unexpectedly exiting after the dialogue closing and sometimes with QXcbConnection: XCB error: 3 (BadWindow).

What I found the problem to be is that the parent of the QFileDialog shouldn't be None or a QMainWindow instance but instead the QMainWindow central widget, e.g. main_window.centralWidget()

claz78
  • 46
  • 1
  • 4