Results 1 to 6 of 6

Thread: Many checkboxes and one slot

  1. #1
    Join Date
    Dec 2009
    Location
    Bratislava, Slovakia
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Many checkboxes and one slot

    hi,
    i have many checkboxes on a dialog (checkBox1, checkBox2, checkBox3...)
    I also store pointers to them in a qlist:

    Qt Code:
    1. QList<QCheckBox* > checkBoxes;
    To copy to clipboard, switch view to plain text mode 

    When i change state of one of them, I want to call a function checking().
    I do it this way:

    Qt Code:
    1. for(int i=0;i<checkBoxes.size();i++)
    2. connect(checkBoxes[i],SIGNAL(clicked()),this,SLOT(checking()));
    To copy to clipboard, switch view to plain text mode 

    It is ok, but what should I do to know which checkBox was clicked inside checking() slot?
    I really don't want to have a slot for each checkBox...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Many checkboxes and one slot

    You can use QObject::sender() or better use QSignalMapper.

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

    mirelon (2nd April 2010)

  4. #3
    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: Many checkboxes and one slot

    For check boxes I'd suggest to use the signal toggled() instead of clicked(), it gives you some more information.
    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.


  5. #4
    Join Date
    May 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Many checkboxes and one slot

    Maybe this could some help for you,
    http://qt.nokia.com/doc/4.6/qbuttongroup.html

  6. #5
    Join Date
    Apr 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Many checkboxes and one slot

    HI ,

    I am newly working with QT .

    i am implementing a list of CheckBox in which i need to write signal and slot . The ctrls are dynamicaly generated based on required count.


    pls send me code if available. on check of checkbox i need to know which checkbox i have checked ...if i get the interger as return fine.

    first checkbox as -"1"
    first checkbox as -"2"
    first checkbox as -"3"

    how i can do it ..pls help me ...

  7. #6
    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: Many checkboxes and one slot

    If only one box can be checked at the same time then place all of them into a QButtonGroup and use API of the latter to learn which of the buttons is checked. And optionally use QRadioButton instances instead of QCheckBox.
    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.


Similar Threads

  1. QFileSystemModel with checkboxes...
    By been_1990 in forum Qt Programming
    Replies: 14
    Last Post: 11th March 2011, 16:01
  2. QTableView and checkboxes
    By ibergmark in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2008, 16:20
  3. checkboxes
    By abrou in forum Newbie
    Replies: 2
    Last Post: 1st February 2008, 19:52
  4. Checkboxes in QAbstractITemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th November 2007, 21:23
  5. how i can add checkboxes to contextMenus?
    By quickNitin in forum Newbie
    Replies: 3
    Last Post: 15th November 2006, 13:35

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.