[PyQt] auto-connected slots (QAction.triggered) seem to be connected twice
Alan Ezust
alan.ezust at gmail.com
Thu Oct 23 18:11:12 BST 2014
I just tried creating a QMainWindow app with Designer integration and I
wanted to
use an auto-connected slot. I am attaching the code here.
The signal is emitted only once, I can see but the auto-connected slot is
called twice for each trigger of the action.
I reproduced this in PtQt 5.2.1 as well as PyQt 3.4.2 on windows 7.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20141023/5d1685ab/attachment.html>
-------------- next part --------------
__author__ = 'aezust'
from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog
from ui_mainwindow import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.actionOpen.triggered.connect(self.other_open)
def other_open(self):
print ("Other Open!!")
def on_actionOpen_triggered(self, extraObj = True):
print ("Open FIle!!")
#QFileDialog.getOpenFileName(self, "Caption", 'c:/users/aezust')
if __name__ == "__main__":
import sys
app =QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec())
-------------- next part --------------
<?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>Text Editor</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSave_As"/>
<addaction name="actionClose"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>Edit</string>
</property>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
<addaction name="actionShow_Hidden"/>
</widget>
<widget class="QMenu" name="menuTools">
<property name="title">
<string>Tools</string>
</property>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
<string>Help</string>
</property>
<addaction name="actionAbout_Qt"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
<addaction name="menuTools"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionSave">
<property name="text">
<string>Save</string>
</property>
</action>
<action name="actionSave_As">
<property name="text">
<string>Save As ...</string>
</property>
</action>
<action name="actionClose">
<property name="text">
<string>Close</string>
</property>
</action>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
</property>
</action>
<action name="actionShow_Hidden">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show Hidden</string>
</property>
</action>
<action name="actionAbout_Qt">
<property name="text">
<string>About Qt</string>
</property>
</action>
<action name="actionOpen">
<property name="text">
<string>Open</string>
</property>
</action>
</widget>
<resources/>
<connections>
<connection>
<sender>actionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>399</x>
<y>299</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections>
</ui>
More information about the PyQt
mailing list