Results 1 to 3 of 3

Thread: PyQt... What am I doing wrong?!

  1. #1
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    3
    Qt products
    Platforms
    Unix/X11 Windows

    Question PyQt... What am I doing wrong?!

    Hi guys, just starting out with Qt using PyQt, and not having a great time! Anyone help me out here... I'm trying to get a button to print "hello world". Stereotypical and unimaginative, I know, but hey, you have to start somewhere! Problem is, I click it and nothing happens! It's not even calling the function. I think my connect statement is rubbish. Can you help?

    Ta,

    Rich

    from PyQt4 import QtCore, QtGui

    Qt Code:
    1. class Ui_About(object):
    2. def setupUi(self, Dialog):
    3. Dialog.setObjectName("Dialog")
    4. Dialog.resize(388, 336)
    5. self.btnOK = QtGui.QPushButton(Dialog)
    6. self.btnOK.setGeometry(QtCore.QRect(130, 300, 110, 23))
    7. self.btnOK.setObjectName("btnOK")
    8.  
    9. QtCore.QObject.connect(self.btnOK, QtCore.SIGNAL("clicked()"), self.hello)
    10. QtCore.QMetaObject.connectSlotsByName(Dialog)
    11.  
    12. def hello(self):
    13. print "hello world"
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: PyQt... What am I doing wrong?!

    Ui_about is not a QObject, it can't have slots. If you modified the code generated by pyuic then don't do it. You should provide your own subclass of QWidget and place the slot there. Consult the docs for using Designer generated components in your application.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Richie (4th September 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    3
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: PyQt... What am I doing wrong?!

    Much appreciated, got it all working now, many thanks.

Similar Threads

  1. QextSerialPort reading error: wrong values
    By Lawand in forum Qt Programming
    Replies: 9
    Last Post: 6th May 2009, 19:29
  2. QMovie supports no animation formats (PyQt on Windows)
    By jmeyer in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2009, 08:44
  3. Replies: 1
    Last Post: 30th July 2008, 23:39
  4. Compiling PyQt with MinGW
    By QuiGon in forum Installation and Deployment
    Replies: 0
    Last Post: 13th April 2008, 07:20
  5. PyQt QTimer problem { FIXED }
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 1st March 2008, 16:50

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.