Results 1 to 14 of 14

Thread: problem connect signal - slot

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

    Default problem connect signal - slot

    Hi! I'm trying to connect two QGroupBox. If the groupbox1 checked or clicked the other groupBox2 be disabled or enabled (setEnabled (false) or setEnabled (true)). In Qt Designer works well.

    Qt Code:
    1. connect(groupBox1, SIGNAL(toggled(bool)), groupBox2, SLOT(setEnabled(bool)));
    To copy to clipboard, switch view to plain text mode 
    ou
    Qt Code:
    1. QObject::connect(groupBox1, SIGNAL(clicked(bool)), groupBox2, SLOT(setEnabled(bool)));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Qt 4.4.3
    To copy to clipboard, switch view to plain text mode 

    Any idea? Thanks

  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

    So, where is the problem? Your code doesn't compile? Or the signal is not emitted? Or slot is not executed?
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem connect signal - slot

    you are right lyuts, where is the problem...?

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

    Default Re: problem connect signal - slot

    My code compiles. I do not know what is wrong (the signal or slot). The code is correct? Which of the two lines would be the best?

  5. #5
    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

    Are you trying to say your code isnt working well,,
    or you want to know which one of toggled() or checked() is better to use ?

  6. #6
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem connect signal - slot

    make sure that its declared in the onstructor..else it wont work ..........

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

    Default Re: problem connect signal - slot

    I'm trying to say that my code compiles, but does not work well.
    When I do:
    Qt Code:
    1. connect(groupBox1, SIGNAL(toggled(bool)), this, SLOT(setEnabled(bool)));
    To copy to clipboard, switch view to plain text mode 
    get result.
    It seems that the slot is not executed when "this" change by "groupBox2".

  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem connect signal - slot

    check the output window. If the connect call fails, it will explain why it failed at runtime.

  9. #9
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem connect signal - slot

    yes ... in your console at run time it will display the warning message like this ..
    Object::connect: No such slot xxx() or Object::connect: No such signal xxx() or any reason ...
    "Behind every great fortune lies a crime" - Balzac

  10. #10
    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 ?

  11. #11
    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.

  12. #12
    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 

  13. #13
    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.

  14. #14
    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, 15:51
  2. qt signal/slot auto-connect issue
    By parnedo in forum Qt Programming
    Replies: 9
    Last Post: 16th July 2009, 13:55
  3. A signal/slot connect isn't working.
    By Daimonie in forum Qt Programming
    Replies: 6
    Last Post: 15th February 2009, 23: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, 20:54
  5. Replies: 12
    Last Post: 18th September 2008, 16: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.