PyQt5 QFileDialog finishes app when called from ch

2019-08-23 10:45发布

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 :))

0条回答
登录 后发表回答