[Tutor] Help with a simple problem

Alan Gauld alan.gauld at btinternet.com
Sat Jan 3 18:28:08 CET 2009


"Saad Javed" <sbjaved at gmail.com> wrote

> I'm trying to create a simple GUI using pyqt4 in which pressing a 
> button
> causes execution of a system command. Here's the code, please help 
> me out. I
> can't figure out whats wrong. Thanks

Caveat: I have never used Qt in my life so this is based on guesswork
and experience of other GUI tookits....

> class TestGui(QtGui.QWidget):
>    def __init__(self, parent=None):
>        QtGui.QWidget.__init__(self, parent)
>        *dial = QtGui.QPushButton('Dial', self)
>        dial.setGeometry(10, 10, 60, 35)
>        self.connect(dial, QtCore.SIGNAL('clicked()'),
>            QtGui.qApp, QtCore.SLOT(os.system('wvdial ptcl')))*

I think the SIGNAL('clicked()') bit is probably supposed to be:

SIGNAL('clicked')

It would be unusual to pass the string representation of a function 
*call*
into a SIGNAL handler, usually you would pass either the function 
object
or the function name.

>        self.connect(quit, QtCore.SIGNAL('clicked()'), QtGui.qApp,
> QtCore.SLOT('quit()'))

And the same here...
Also in the SLOT call you do something inconsistent.
In the first case you do not quote the action in the other you do
quote it. So I suspect that they should both be quoted?

But as I say thats guesswork!

Alan G.




More information about the Tutor mailing list