Results 1 to 2 of 2

Thread: PyQT connect problem

  1. #1
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default PyQT connect problem

    I have this code:

    Qt Code:
    1. def CreateActions(self):
    2. global openAct
    3. openAct = QtGui.QAction("Open", self)
    4. openAct.setShortcut("Ctrl+O")
    5. self.connect(openAct, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("self.Open(self)"))
    6. def Open(self):
    7. print "test\n"
    To copy to clipboard, switch view to plain text mode 

    When I click the open button in my menu, nothing happens. When the code runs there are no errors. What is the problem?

  2. #2
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQT connect problem

    I have this now:

    Qt Code:
    1. def CreateActions(self):
    2. global openAct
    3. openAct = QtGui.QAction("Open", self)
    4. openAct.setShortcut("Ctrl+O")
    5. #openAct.triggered.connect(self.Open())
    6. QtCore.QObject.connect(openAct, QtCore.SIGNAL("triggered()"), self, self.Open())
    7. def CreateMenus(self):
    8. menubar = self.menuBar()
    9. fileMenu = menubar.addMenu("&File")
    10. fileMenu.addAction(openAct)
    11. def Open(self):
    12. print "test\n"
    13. fileName = QtGui.QFileDialog. \
    14. getOpenFileName(self, "Open File",
    15. QtCore.QDir.currentPath(),
    16. "NetDMF Files (*.xml *.xmf *.xmn)")
    To copy to clipboard, switch view to plain text mode 

    The "test" is printed, but the Open() method is executed as soon as I run the code. The program does not wait for me to click the Open action.

    If I have this code:
    Qt Code:
    1. def CreateActions(self):
    2. global openAct
    3. openAct = QtGui.QAction("Open", self)
    4. openAct.setShortcut("Ctrl+O")
    5. #openAct.triggered.connect(self.Open())
    6. QtCore.QObject.connect(openAct, QtCore.SIGNAL("triggered()"), self, self.Open())
    7. def CreateMenus(self):
    8. menubar = self.menuBar()
    9. fileMenu = menubar.addMenu("&File")
    10. fileMenu.addAction(openAct)
    11. def Open(self):
    12. print "test\n"
    To copy to clipboard, switch view to plain text mode 

    I get this error:
    TypeError: argument 4 of QObject.connect() has an invalid type

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  2. connect problem
    By liengen in forum Newbie
    Replies: 2
    Last Post: 22nd October 2008, 16:21
  3. signal-slot problem with QVector
    By stefan in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2008, 13:58
  4. Replies: 7
    Last Post: 15th February 2006, 11:34

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.