[PyQt] Question about the segmentation fault induced by uic.loadUiTyp

lzf neu lzfneu at live.com
Wed Mar 21 08:04:34 GMT 2018


I am not using the official centos qt4 and pyqt4. I installed them by the unfolding the downloaded tar.gz packages and run by normal console. I found that this was the reason to cause the problem. Therefore, I used the make uninstall command to uninstall the unofficial qt4 and pyqt4 then reboot, and then make install pyqt4 again, then the problem has solevd.
Many thanks for your reminder.

From: Baz Walter<mailto:bazwal at gmail.com>
Date: 2018-03-20 02:41
To: pyqt<mailto:pyqt at riverbankcomputing.com>
Subject: Re: [PyQt] Question about the segmentation fault induced by uic.loadUiTyp
On 19/03/18 09:35, lzf neu wrote:
> The whole script that I referenced from the website is as follows:
> http://pythonforengineers.com/your-first-gui-app-with-python-and-pyqt/
> ######################################################
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> import sys
> from PyQt4 import QtCore, QtGui, uic
>
> qtCreatorFile = "a.ui"  # a.ui is in my case
>
> Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
>
> class MyApp(QtGui.QMainWindow, Ui_MainWindow):
>      def __init__(self):
>          QtGui.QMainWindow.__init__(self)
>          Ui_MainWindow.__init__(self)
>          self.setupUi(self)
>
>      def CalculateTax(self):
>          price=int(self.price_box.toPlainText())
>          tax=(self.tax_rate.value())
>          total_price=price+((tax/100)*price)
>          total_price_string="The total price with tax is: " + str(total_price)
>          self.results_window.setText(total_price_string)
>
> if __name__ == "__main__":
>      app = QtGui.QApplication(sys.argv)
>      window = MyApp()
>      window.show()
>      self.calc_tax_button.clicked.connect(self.CalculateTax)
>      sys.exit(app.exec_())
> ###########################################################
>
> I run the whole example script and the terminal still shows:  Segmentation fault (core dumped)
>
> Then I run the script line by line and found that the error occured at the line:  Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)

The only thing wrong with that script is the line that attempts to make
a signal/slot connection. That will obviously raise a NameError because
self is not defined in that scope. So it needs to go in the __init__
method of the MyApp class.

When I fix that, the script runs perfectly fine for me (using qt 4.8.7
and pyqt 4.12.1, with either python 3.6.4 or python 2.7.14). Contrary to
what others have said, it is not necessary to create a QApplication
before calling uic.loadUiType. All that does is use exec to load a
module and return a class object - it does not create an instance of
anything.

Are you using the *official* CentOS qt4, pyqt4 and python2 packages? Or
did you install some or all of them in some other way? And how exactly
are you running the script? Are you doing it via some kind of IDE, or
just using a normal console?
_______________________________________________
PyQt mailing list    PyQt at riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180321/3ece3c89/attachment.html>


More information about the PyQt mailing list