Results 1 to 14 of 14

Thread: problem connect signal - slot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem connect signal - slot

    Can you tell the declaration of groupBox2 ?

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem connect signal - slot

    You need to write your own slot which will call setEnabled() for the second groupbox. Here what the documentation says about toggled(bool) signal:
    Qt Code:
    1. If the group box is checkable, this signal is emitted when the check box is toggled. on is true if the check box is checked; otherwise it is false.
    To copy to clipboard, switch view to plain text mode 
    It means that when you enable your first group box the signal is emitted with 'true' and as a result you call setEnabled(true) for your second group box. But as I understand you need to to invert that bool flag. The same thing with clicked() signal.

    You need your own signal, smth like this:
    Qt Code:
    1. connect(groupBox1, SIGNAL(toggled(bool)), this, SLOT(mySlot(bool)));
    2. ...
    3. void
    4. mySlot(bool ipFlag)
    5. {
    6. groupBox2->setEnabled(!ipFlag);
    7. }
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  3. #3
    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: problem connect signal - slot

    Quote Originally Posted by lyuts View Post
    Qt Code:
    1. connect(groupBox1, SIGNAL(toggled(bool)), this, SLOT(mySlot(bool)));
    2. ...
    3. void
    4. mySlot(bool ipFlag)
    5. {
    6. groupBox2->setEnabled(!ipFlag);
    7. }
    To copy to clipboard, switch view to plain text mode 
    For that you can simply use QWidget::setDisabled().
    Qt Code:
    1. connect(groupBox1, SIGNAL(toggled(bool)), groupBox2, SLOT(setDisabled(bool)));
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem connect signal - slot

    Yes, Lykurg, you are right. How could i miss such an obviuos thing.
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem connect signal - slot

    Thanks guys! The help of all was very important.

Similar Threads

  1. Replies: 8
    Last Post: 27th August 2009, 14:51
  2. qt signal/slot auto-connect issue
    By parnedo in forum Qt Programming
    Replies: 9
    Last Post: 16th July 2009, 12:55
  3. A signal/slot connect isn't working.
    By Daimonie in forum Qt Programming
    Replies: 6
    Last Post: 15th February 2009, 22:55
  4. Connect signal from base to slot of sub-sub-object
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 30th October 2008, 19:54
  5. Replies: 12
    Last Post: 18th September 2008, 15:04

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
  •  
Qt is a trademark of The Qt Company.