[PyKDE] (no subject)

Jim Bublitz jbublitz at nwinternet.com
Thu Feb 26 09:04:00 GMT 2004


On Wednesday February 25 2004 22:53, ankarp at charter.net wrote:
> Hello to all,
>
> While playing with PyQt, I attempted to reimplement
> in it a few C++ examples from the Qt distribution.
> Working on the example from
>
> <...>/qt-devel-XXX/examples/mdi
>
> (which compiles and runs properly in C++) I encountered
> the following problem, shown here in the most minimal
> form for illustration:
>
> ##########################
>
> import sys
> from qt import *
>
> class ApplicationWindow(QMainWindow):
>     def __init__(self):
>         QMainWindow.__init__(self,None,
>              "example application main window",
>               Qt.WDestructiveClose)
>         self.fileTools = QToolBar(self, "file operations")
>         self.addDockWindow(self.fileTools,
>              "File operations",
>               QMainWindow.DockTop, True)
>         openIcon = QPixmap([]) # empty pixmap, for brevity
>         openIconSet = QIconSet(openIcon)
>         fileOpen = QToolButton(openIconSet, "Open File",
>               None, self, SLOT("load()"), self.fileTools,
>               "open file" )
>
>     def load(self):
>         print "DEBUG: called load()..."
>
>
> def main(argv):
>     app=QApplication(sys.argv)
>     window=ApplicationWindow()
>     window.show()
>     app.connect(app, SIGNAL('lastWindowClosed()'), app,
>          SLOT('quit()'))
>     app.exec_loop()
>
> if __name__=="__main__":
>     main(sys.argv)
>
> ##########################################
>
> When running it I get a window show up fine, but
> also the following messages:
>
> bash$ python mdimin.py
> QObject::connect: No such slot QMainWindow::load()
> QObject::connect:  (sender name:   'open file')
> QObject::connect:  (receiver name: 'example application main
> window')
>
> In other words, self is not recognized as having type
> ApplicationWindow. Does anybody know how to fix this?
>
> The same error occurs when I try to connect to the slot
> in other ways, for example, while still in
> ApplicationWindow.__init__():
>
> file = QPopupMenu(self)
> id = file.insertItem( openIconSet, "&Open...",
>                       self, SLOT("load()"),
>                       Qt.CTRL+Qt.Key_O )
>
>
> Additional info: this is PyQt-3.10, Qt version 3,
> on Redhat 9 (kernel 2.4.20)
>
> Thanks for any help!


Where C++ Qt specifies:
     
    QObject * receiver, const char * slot,

use only a single argument - the slot method (can be a class 
method or a plain old global function).

For example:
id = file.insertItem( openIconSet, "&Open...",
                       self.load,
                       Qt.CTRL+Qt.Key_O )

should work.

The general form for QObject::connect in Python would be:

    self.connect (self.something, 
        SIGNAL ("clicked()"),  
        self.slot)

Assuming 'self' is a QObject subclass and 'self.something' has a 
clicked() signal.

The argument to SIGNAL is the full C++ signature (*, &, const, 
and everything else left in for the args, but no variable 
names). The slot method is specified by its "address", ie - no 
() or args - but args have to correspond to the signal's (plus 
"self" if a class method).

I'm not sure exactly when you'd use SLOT - I don't think I've 
ever found a need for it.

Jim




More information about the PyQt mailing list