[PyQt] Having trouble emitting and connecting SIGNALS

Entity Reborn entityreborn at gmail.com
Sat Mar 5 20:20:49 GMT 2011


For some reason, with this code, I cannot get newitemfunc called.

>  from PyQt4 import QtCore, QtGui
>
> import sys
>
>
>> def newitemfunc(parentitem, newitem):
>
>     print("newitem")
>
>
>> class class1(QtCore.QObject):
>
>     pass
>
>
>> class class2(QtCore.QAbstractItemModel):
>
>     def test1(self, data):
>
>         return self.test2(data, class1())
>
>
>>     def test2(self, data, curitem):
>
>         if "SubItems" in data:
>
>             for item in data["SubItems"]:
>
>                 newitem = class1()
>
>                 print("emitting")
>
>                 newitem.emit(QtCore.SIGNAL("newitem"), newitem)
>
>                 self.test2(item, newitem)
>
>
>> class MainWindow(QtGui.QMainWindow):
>
>     def __init__(self, data, *args):
>
>         super(MainWindow, self).__init__(*args)
>
>         self.model = class2()
>
>         print("connecting")
>
>         self.connect(self.model, QtCore.SIGNAL("newitem"), newitemfunc)
>
>         self.model.test1(data)
>
>
>
> app = QtGui.QApplication(sys.argv)
>
>
>> data = {
>
>     "Title": "Title",
>
>     "Summary": "Summary",
>
>     "SubItems": [
>
>         {
>
>             "Title": "Item 1",
>
>             "Summary": "A basic item",
>
>             "SubItems": [
>
>                 {
>
>                     "Title": "SubItem1.1",
>
>                     "Summary": "Sub item one of item one",
>
>                 },
>
>             ]
>
>         },
>
>         {
>
>             "Title": "CheckBoxItem",
>
>             "Summary": "A second item, currently a little bugged. (Should
>> be flush to the left)",
>
>             "CheckBoxType": "CheckBox",
>
>             "Checked": True,
>
>         },
>
>         {
>
>             "Title": "RadioItems",
>
>             "Summary": "A third radio item",
>
>             "SubItems": [
>
>                 {
>
>                     "Title": "SubItem1.1",
>
>                     "Summary": "Sub item one of item three",
>
>                     "CheckBoxType": "Radio",
>
>                     "Checked": False,
>
>                 },
>
>                 {
>
>                     "Title": "SubItem1.2",
>
>                     "Summary": "Sub item two of item three",
>
>                     "CheckBoxType": "Radio",
>
>                     "Checked": True,
>
>                 },
>
>                 {
>
>                     "Title": "SubItem1.3",
>
>                     "Summary": "Sub item three of item three",
>
>                     "CheckBoxType": "Radio",
>
>                     "Checked": False,
>
>                 },
>
>             ]
>
>         },
>
>     ],
>
> }
>
>
>> window = MainWindow(data)
>
> window.show()
>
>
>> sys.exit(app.exec_())
>
>
-- 
~EntityReborn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110305/1b595478/attachment-0001.html>


More information about the PyQt mailing list