[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Question about the segmentation fault induced by uic.loadUiTyp
From:       lzf neu <lzfneu () live ! com>
Date:       2018-03-21 8:04:34
Message-ID: KL1PR06MB1221BFECACA6D270F0137426ADAA0 () KL1PR06MB1221 ! apcprd06 ! prod ! outlook ! com
[Download RAW message or body]

[Attachment #2 (text/plain)]

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@gmail.com>
Date: 2018-03-20 02:41
To: pyqt<mailto:pyqt@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@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[Attachment #3 (text/html)]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; \
margin-left: 0.5em; }body { font-size: 10.5pt; font-family: 'Microsoft YaHei UI'; \
color: rgb(0, 0, 0); line-height: 1.5; }</style> </head>
<body>
<div><span style="font-size: 10.5pt; line-height: 1.5; background-color: window;">I \
am not using the&nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5; \
background-color: window;">official</span><span style="font-size: 10.5pt; \
line-height: 1.5; background-color: window;">&nbsp;centos  qt4 and pyqt4. I installed \
them by the unfolding the downloaded tar.gz packages and run by normal console. I \
found&nbsp;that this was the reason to cause the problem</span><span \
style="font-size: 10.5pt; line-height: 1.5; background-color: \
window;">.&nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5; \
background-color: window;">Therefore,  I used the make uninstall command to uninstall \
the unofficial qt4 and pyqt4 then reboot, and then make install pyqt4 \
again,&nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5; \
background-color: window;">then the problem has solevd. &nbsp;</span></div> \
<div><span style="background-color: window; font-size: 10.5pt; line-height: \
1.5;">Many thanks for your reminder.</span></div> <div><br>
</div>
<blockquote style="margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;">
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<div style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-SIZE: \
12px;FONT-FAMILY:tahoma;COLOR:#000000; BACKGROUND: #efefef; PADDING-BOTTOM: 8px; \
PADDING-TOP: 8px"> <div><b>From:</b>&nbsp;<a href="mailto:bazwal@gmail.com">Baz \
Walter</a></div> <div><b>Date:</b>&nbsp;2018-03-20&nbsp;02:41</div>
<div><b>To:</b>&nbsp;<a href="mailto:pyqt@riverbankcomputing.com">pyqt</a></div>
<div><b>Subject:</b>&nbsp;Re: [PyQt] Question about the segmentation fault induced by \
uic.loadUiTyp</div> </div>
</div>
<div>
<div>On 19/03/18 09:35, lzf neu wrote:</div>
<div>&gt; The whole script that I referenced from the website is as follows:</div>
<div>&gt; http://pythonforengineers.com/your-first-gui-app-with-python-and-pyqt/</div>
 <div>&gt; ######################################################</div>
<div>&gt; #!/usr/bin/env python</div>
<div>&gt; # -*- coding: utf-8 -*-</div>
<div>&gt; </div>
<div>&gt; import sys</div>
<div>&gt; from PyQt4 import QtCore, QtGui, uic</div>
<div>&gt; </div>
<div>&gt; qtCreatorFile = &quot;a.ui&quot;&nbsp; # a.ui is in my case</div>
<div>&gt; </div>
<div>&gt; Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)</div>
<div>&gt; </div>
<div>&gt; class MyApp(QtGui.QMainWindow, Ui_MainWindow):</div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):</div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
QtGui.QMainWindow.__init__(self)</div> \
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
Ui_MainWindow.__init__(self)</div> \
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.setupUi(self)</div> <div>&gt; </div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def CalculateTax(self):</div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
price=int(self.price_box.toPlainText())</div> \
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
tax=(self.tax_rate.value())</div> \
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
total_price=price&#43;((tax/100)*price)</div> \
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
total_price_string=&quot;The total price with tax is: &quot; &#43; \
str(total_price)</div> \
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.results_window.setText(total_price_string)</div> <div>&gt; </div>
<div>&gt; if __name__ == &quot;__main__&quot;:</div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; app = QtGui.QApplication(sys.argv)</div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window = MyApp()</div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.show()</div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
self.calc_tax_button.clicked.connect(self.CalculateTax)</div> \
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.exit(app.exec_())</div> <div>&gt; \
###########################################################</div> <div>&gt; </div>
<div>&gt; I run the whole example script and the terminal still shows:&nbsp; \
Segmentation fault (core dumped)</div> <div>&gt; </div>
<div>&gt; Then I run the script line by line and found that the error occured at the \
line:&nbsp; Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)</div> \
<div>&nbsp;</div> <div>The only thing wrong with that script is the line that \
attempts to make </div> <div>a signal/slot connection. That will obviously raise a \
NameError because </div> <div>self is not defined in that scope. So it needs to go in \
the __init__ </div> <div>method of the MyApp class.</div>
<div>&nbsp;</div>
<div>When I fix that, the script runs perfectly fine for me (using qt 4.8.7 </div>
<div>and pyqt 4.12.1, with either python 3.6.4 or python 2.7.14). Contrary to </div>
<div>what others have said, it is not necessary to create a QApplication </div>
<div>before calling uic.loadUiType. All that does is use exec to load a </div>
<div>module and return a class object - it does not create an instance of </div>
<div>anything.</div>
<div>&nbsp;</div>
<div>Are you using the *official* CentOS qt4, pyqt4 and python2 packages? Or </div>
<div>did you install some or all of them in some other way? And how exactly </div>
<div>are you running the script? Are you doing it via some kind of IDE, or </div>
<div>just using a normal console?</div>
<div>_______________________________________________</div>
<div>PyQt mailing list&nbsp;&nbsp;&nbsp; PyQt@riverbankcomputing.com</div>
<div>https://www.riverbankcomputing.com/mailman/listinfo/pyqt</div>
</div>
</blockquote>
</body>
</html>


[Attachment #4 (unknown)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic