Results 1 to 5 of 5

Thread: Passing additional arguments to a slot in pyqt4

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2015
    Posts
    3
    Qt products
    Platforms
    Unix/X11

    Smile Passing additional arguments to a slot in pyqt4

    Hi,

    In my current code, when the user highlights an item in a combo box, the index gets passed to a function like so below:

    self.tab2TrajectoryCombo.highlighted.connect(self. trajectorychanged)
    .
    .
    .
    def trajectorychanged(self, value):
    '''trajectory changed'''

    self.pcgraphs.changetrajectory(int(str(value)))
    self.tab2TrajectoryCombo.setCurrentIndex(int(str(v alue)))
    self.tab3TrajectoryCombo.setCurrentIndex(int(str(v alue)))

    The above works nicely. However, I want to pass an argument to the function in addition to the index from the combobox. So I would do something like:

    self.tab2TrajectoryCombo.highlighted.connect(lambd a: self.trajectorychanged(2))
    .
    .
    .
    def trajectorychanged(self, value, numbertwo):
    '''trajectory changed'''

    self.pcgraphs.changetrajectory(int(str(value)))
    self.tab2TrajectoryCombo.setCurrentIndex(numbertwo )
    self.tab3TrajectoryCombo.setCurrentIndex(numbertwo )

    The above code doesn't work though. The error is:

    Traceback (most recent call last):
    File "/users/gareths/workspace/pyPczplotGUINew/tabwidget.py", line 55, in <lambda>
    self.tab2TrajectoryCombo.highlighted.connect(lambd a: self.trajectorychanged(2))
    TypeError: trajectorychanged() takes exactly 3 arguments (2 given)

    Does anyone know how to do this?

    Many thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Passing additional arguments to a slot in pyqt4

    Is the value associated with the entry in the combobox or with the location on where you make the connect?

    If the former: you can attach any data to a combobox entry using the setItemData() method and retrieve it again with itemData().

    Btw: in you attempt you are using that other value to change the value of the combobox again, leading to yet another change signal emit

    Cheers,
    _

Similar Threads

  1. Passing arguments to compiler
    By aaditya190 in forum Newbie
    Replies: 3
    Last Post: 18th December 2013, 10:41
  2. Replies: 2
    Last Post: 24th February 2013, 10:16
  3. Passing arguments
    By papillon in forum Qt Programming
    Replies: 3
    Last Post: 8th August 2012, 23:44
  4. Replies: 12
    Last Post: 7th September 2010, 12:53
  5. passing arguments in SLOT
    By eleanor in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2008, 21:55

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.