Change remove button signal emission to new style signals.

This commit is contained in:
Patrick Zimmermann 2013-02-19 23:58:29 +01:00
parent 0df1f3932a
commit 3c8c136d3d
2 changed files with 14 additions and 4 deletions

View File

@ -331,9 +331,7 @@ class DuplicateSongRemovalForm(OpenLPWizard):
self.songs_horizontal_layout.addStretch()
for duplicate in self.duplicate_song_list[-1]:
song_review_widget = SongReviewWidget(self.review_page, duplicate)
QtCore.QObject.connect(song_review_widget,
QtCore.SIGNAL(u'song_remove_button_clicked(PyQt_PyObject)'),
self.remove_button_clicked)
song_review_widget.song_remove_button_clicked.connect(self.remove_button_clicked)
self.songs_horizontal_layout.addWidget(song_review_widget)
self.songs_horizontal_layout.addStretch()
self.songs_horizontal_layout.addStretch()

View File

@ -42,6 +42,18 @@ class SongReviewWidget(QtGui.QWidget):
The remove logic is not implemented here, but a signal is provided
when the remove button is clicked.
"""
# Signals have to be class variables and not instance variables. Otherwise
# they are not registered by Qt (missing emit and connect methods are artifacts of this).
# To use SongReviewWidget as a signal parameter one would have to assigning the class
# variable after the class is declared. While this is possible, it also messes Qts meta
# object system up. The result is an
# "Object::connect: Use the SIGNAL macro to bind SongReviewWidget::(QWidget*)" error on
# connect calls.
# That's why we cheat a little and use QWidget instead of SongReviewWidget as parameter.
# While not being entirely correct, it does work.
song_remove_button_clicked = QtCore.pyqtSignal(QtGui.QWidget)
def __init__(self, parent, song):
"""
``parent``
@ -168,4 +180,4 @@ class SongReviewWidget(QtGui.QWidget):
"""
Signal emitted when the "remove" button is clicked.
"""
self.emit(QtCore.SIGNAL(u'song_remove_button_clicked(PyQt_PyObject)'), self)
self.song_remove_button_clicked.emit(self)