简体   繁体   中英

Python & PyQt4 - a program with plugins. Can't connect signals from plugins to UI

I'm writing a program in Python and PyQt4 with plugins support. Plugins are loaded at startup (with __import__ ), adding elements to UI (ie adding a new tab to tab widget, methods from mainclass exposed and everything is working at this point). My problem is signal ignoring, ie:

from lib.plugin import Plugin
from plugins.dsc.ui import dsc_main

class DSC(Plugin):
    def __init__(self):
        Plugin.__init__(self)

        # Load ui
        self.dsc_widget = QTabWidget()
        self.dsc_ui = dsc_main.Ui_Form()
        self.dsc_ui.setupUi(self.dsc_widget)

        # QWidget form contains a QListWidget, so filling it with
        # something.
        for x in range(0, 100):
            self.dsc_ui.list_widget.addItem(str(x))

        # This isn't working
        self.dsc_ui.list_widget.currentItemChanged.connect(self.show_data)
        # This also isn't working
        self.dsc_ui.list_widget.itemClicked.connect(self.show_data)

    def show_data(self):
        print "WUT?"

I've also tried qDebug instead of print, but no effect here. I've also tried connecting widgets from dsc_ui thru main form thread (by exposing a method that finds child this name and connect it to function), but this was also effectless.

This question is similar to this one , but everything described in answer already tried.

Is there any good way I missed?

Is your Pugin class inherited from QObject ? If not, you must inherit DSC from QObject first and call the QObject.__init__ in your __init__ method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM