Results 1 to 4 of 4

Thread: Qpushbutton clicked()

  1. #1
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qpushbutton clicked()

    Hi, I want to know, how to send some parameters when QPushButton is clicked...I have array 8x8 of buttons, and i need for each button to send its x and y coordinates...like when button[4][5] is pressed, it calls function f(4,5), how can i do that ? Thanks

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton clicked()

    Have a look at QSignalMapper. It comes close your needs. Unfortunately, it allows only one parameter to be sent. But maybe, you can code your mapping as string, so a function f(const QString&) could be called as f("4,5") and inside f() you split the string into integers 4 and 5.

  3. #3
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton clicked()

    Thanks! That's exactly what I needed!

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qpushbutton clicked()

    A cleaner way to do this is to derive a new QPushbutton class that connects its own clicked() signal to an internal slot where a signal is emitted carrying the button's coordinates. Classes that connect to this signal don't need to know anything about the internal structure that emits it, and they don't have to parse a string to extract integers. The whole implementation requires just a few lines of code.

Similar Threads

  1. QCalendarWidget::clicked
    By ouekah in forum Newbie
    Replies: 6
    Last Post: 2nd May 2010, 16:37
  2. Replies: 0
    Last Post: 22nd February 2010, 09:30
  3. connectSlotsByName and clicked()
    By becrux in forum Qt Programming
    Replies: 5
    Last Post: 2nd December 2009, 07:05
  4. QPushButton color when clicked
    By ntp in forum Qt Programming
    Replies: 3
    Last Post: 30th April 2008, 18:34
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

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.