Results 1 to 10 of 10

Thread: QGroupBox and signal clicked(bool)

  1. #1
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGroupBox and signal clicked(bool)

    I have a GUI done with designer (qt4)

    it has a groupbox: theGroup
    it has some radiobuttons: radio0, radio1, radio2;
    it has a listwidget: monitor

    then i've created a class MyClass which is derived from the gui.

    I try to create a connection:
    Qt Code:
    1. void theGroup::on_theGroup_clecked(bool )
    2. {
    3. qDebug("done.");
    4. }
    To copy to clipboard, switch view to plain text mode 

    the result is that there is no msg on the console.
    Then i tried to connect the radiobutton signal with a slot i've created and it works fine. I am lost.

  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: QGroupBox and signal clicked(bool)

    QGroupBox emits clicked() signal in case it's a checkable group box and the check state of the group box changes. QGroupBox::clicked() is NOT emitted when an arbitrary checkbox/radiobutton/anything else inside the group box changes its check state.
    J-P Nurmi

  3. #3
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGroupBox and signal clicked(bool)

    Find the bug!

    I haven't understand the documentation well.

    This signal works when the check box is activated.
    The question now is: is there a way to have just one connection for all radiobuttons signal clicked in the qgroupbox or i have to make a connection for each radiobutton siglan?

  4. #4
    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: QGroupBox and signal clicked(bool)

    J-P Nurmi

  5. #5
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGroupBox and signal clicked(bool)

    it is working! one way...
    Qt Code:
    1. QGroupButton *myGroup;
    To copy to clipboard, switch view to plain text mode 
    in the constructor I've make a connection
    Qt Code:
    1. connect(myGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(mySlot()));
    To copy to clipboard, switch view to plain text mode 
    and it works fine
    i tried the qt4 way:
    Qt Code:
    1. void on_myGroup_buttonClicked( QAbstractButton * button );
    To copy to clipboard, switch view to plain text mode 

    and i get this error at runtime:
    QMetaObject::connectSlotsByName: No matching signal for on_myGroup_buttonClicked(QAbstractButton*)

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGroupBox and signal clicked(bool)

    QMetaObject matches QObject names --- it cannot see variables. Use QObject::setName().

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

    Default Re: QGroupBox and signal clicked(bool)

    i've done it. the function is QObject::setObjectName().

    the next problem is that I've set the name in the constructor but the signal - slot connection it has been already done at this point.

    So i think that I should create a new class which is derived from QButtonGroup and has a constructor with a chance to set a name.
    or is there a better solution?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGroupBox and signal clicked(bool)

    Quote Originally Posted by codebehind View Post
    the next problem is that I've set the name in the constructor but the signal - slot connection it has been already done at this point.
    QMetaObject::connectSlotsByName() is called by setupUi(), so you have to create your button group earlier.

    Quote Originally Posted by codebehind View Post
    or is there a better solution?
    Just initialize it before invoking setupUi() or make the connection using QObject::connect().

  9. The following user says thank you to jacek for this useful post:

    codebehind (30th August 2008)

  10. #9
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGroupBox and signal clicked(bool)

    it works.
    a little detail - if you make ui with the designer, then you shoul put setupUi() befor any calling of other objects
    for example:
    I've add some radiobuttons (created with the designer) to the QButtonGroup. If i add those radio buttons to the buttongroup befor calling setupUi() the result is Segmentation Fault.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGroupBox and signal clicked(bool)

    Quote Originally Posted by codebehind View Post
    If i add those radio buttons to the buttongroup befor calling setupUi() the result is Segmentation Fault.
    That's because setupUi() creates all of the widgets from the .ui file. Before you invoke it you just have uninitialized pointers.

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.