I am working on the Pyqt5 application related to python. I am new to python. I am not able to understand the usage of pyqtSignal, how to use and where to use it. I tried searching youtube https://www.youtube.com/watch?v=LfztdwaGOjs&list=LL&index=1. Got a small video in spanish explaining the pyqtsignal. I typed the code. I am not able to execute it. I am getting the error- TypeError: ('Wrong base class of toplevel widget', (<class 'dialog.Dialog'>, 'QMainWindow'))
Please explain me the pyqtsignal usage in python.
The code is as below:
dialog.py
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import uic
class Dialog(QDialog):
listWidgetTieneMultiploDe5= pyqtSignal()
def __init__(self):
QDialog.__init__(self)
uic.loadUi("dialog.ui",self)
self.agregarButton.clicked.connect(self.onAgregarButtonClicked)
self.listWidgetTieneMultiploDe5.connect(self.onListWidgetTienemultiploDe5)
def onAgregarButtonClicked(self):
self.listWidget.addItem("Hola, mundo")
if self.listWidget.Count()%5==0:
self.listWidgetTieneMultiploDe5.emit()
def onListWidgetTienemultiploDe5(self):
QMessageBox.information(self,"OK","Muliple de 5")
main.py
from PyQt5.QtWidgets import QApplication
from dialog import Dialog
import sys
app= QApplication(sys.argv)
app.setStyle("fusion")
w=Dialog()
w.show()
sys.exit(app.exec_())
dialog.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="agregarButton">
<property name="text">
<string>Agregar</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QListView" name="listView"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>