Results 1 to 3 of 3

Thread: Which QCheckBox is checked?

  1. #1
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Which QCheckBox is checked?

    I have a list of dynamically created QCheckBoxes as:

    Qt Code:
    1. for (int d=0; d<5; ++d)
    2. {
    3. QCheckBox *checkBox = new QCheckBox(names[d], this);
    4. sendToLayout->addWidget(checkBox);
    5. connect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(handleDestinationChange(int)));
    6. }
    To copy to clipboard, switch view to plain text mode 

    I get the callback in the slot handleDestinationChange method. I want to do the same thing when each is checked, I just want to use the QString from checkBox->text() in the slot. The question is, how can I tell which of the 5 check boxes was the one that was checked? Only the check state is passed to the slot.

    Thanks for any ideas.

    Craig
    Last edited by wysota; 9th November 2007 at 00:32. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Which QCheckBox is checked?

    You can use QSignalMapper or QObject::sender() to identify the sender.
    J-P Nurmi

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

    Craig.Smith (9th November 2007)

  4. #3
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Which QCheckBox is checked?

    Thanks! The QObject::sender() was exactly what I needed. It worked like a charm.

Similar Threads

  1. How QCheckBox into QListWidgetItem?
    By Teuniz in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2007, 21:31
  2. qCheckbox back ground color
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2006, 19:44
  3. Insert QCheckBox into QTableView
    By wind in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2006, 17:15
  4. Iterate and get Checked QTable items??
    By darpan in forum Newbie
    Replies: 2
    Last Post: 10th May 2006, 19:27
  5. No action checked in an exclusive action group
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 13th February 2006, 07:19

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.