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

List:       pykde
Subject:    [PyQt] Signal and slot not always working
From:       "s.achterop () rug ! nl" <s ! achterop () rug ! nl>
Date:       2017-03-29 17:48:51
Message-ID: 464e0ce1-fefe-bf0b-1aca-9238943e82d9 () rug ! nl
[Download RAW message or body]

    Hello list,

I have some problems to get signals/slots to work.
Simple examples work, but in an example using QtDesigner generated code the slot never is called.
In the code below you find the "connect" method called in two places.
As is, the program DOES NOT work, in the sense that it does not end when the button is pressed.

When the other "connect", now comment, is used, clicking of the button DOES end the program.
The question is of course, what am I doing wrong?

Thanks in advance:

================= main.py
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QMainWindow
from PyQt5.QtCore import qDebug, QCoreApplication, pyqtSignal, pyqtSlot

from ui import Ui_Widget

class MyMainWindow(QMainWindow, Ui_Widget):
     def __init__(self):
         super().__init__()
         self.ui = Ui_Widget()
         self.ui.setupUi(self)
# doesn't work!
         self.ui.pushButton.clicked.connect(QCoreApplication.instance().quit)


if __name__ == "__main__":
     app = QApplication(sys.argv)
     MainWindow = QMainWindow()
     ui = MyMainWindow()
     ui.setupUi(MainWindow)
     MainWindow.show()
     sys.exit(app.exec_())

===========  ui.y
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Widget(object):
     def setupUi(self, Widget):
	Widget.setObjectName("Widget")
	Widget.resize(400, 300)
	self.pushButton = QtWidgets.QPushButton(Widget)
         self.pushButton.setGeometry(QtCore.QRect(160, 60, 87, 27))
         self.pushButton.setObjectName("pushButton")

         self.retranslateUi(Widget)
         QtCore.QMetaObject.connectSlotsByName(Widget)
# this one does work!
#        self.pushButton.clicked.connect(QtCore.QCoreApplication.instance().quit)

     def retranslateUi(self, Widget):
	_translate = QtCore.QCoreApplication.translate
	Widget.setWindowTitle(_translate("Widget", "Widget"))
	self.pushButton.setText(_translate("Widget", "PushButton"))
======= end of programs
_______________________________________________
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