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

lzf neu lzfneu at live.com
Mon Mar 19 09:35:49 GMT 2018


Hi Florian,

Thanks for your reply. 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)

Any suggestions will be appreciated and thank you very much.

Zhefu
From: Florian Bruhin<mailto:me at the-compiler.org>
Date: 2018-03-19 13:21
To: lzf neu<mailto:lzfneu at live.com>
CC: pyqt<mailto:pyqt at riverbankcomputing.com>
Subject: Re: [PyQt] Question about the segmentation fault induced by uic.loadUiTyp
Hi,

On Mon, Mar 19, 2018 at 03:48:45AM +0000, lzf neu wrote:
> My simple testing script is as follows:
> #============================
> import sys
> from PyQt4 import QtCore, QtGui, uic
> uic.loadUiType("a.ui")      # the GUI generated by qt-designer saved as a.ui
> #============================
>
> When running to the last line, an error ocurred and shows in the terminal:
> Segmentation fault (core dumped)

I'm guessing you need to create a QApplication first.

> My installing enviroments are: CentOs7, PyQt4_gpl_x11-4.12.1,
> qt-everywhere-opensource-src-4.8.7, sip-4.19.8,  QtPy-1.4.0, and the
> python version of CentOs7 is 2.7.5

Let me note that those are ~3 years old and unsupported/end-of-life
since a while.

Florian

--
https://www.qutebrowser.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180319/3f44242d/attachment.html>


More information about the PyQt mailing list