Results 1 to 7 of 7

Thread: [solved] QObject::connect: No such signal QGroupBox::toggled(int, bool)

  1. #1
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default [solved] QObject::connect: No such signal QGroupBox::toggled(int, bool)

    Hi,

    I am trying to connect a custom signal from a custom object to my main window. The custom object is derived from a QGroupBox. I think I set up the signal correctly because auto complete picks it up when I write the connect statement but when I run the program I get the information that there is no such signal in QGroupBox. Why is the program trying to connect a QGroupBox when I used a custom object??? If I use a signal from QGroupBox the program runs fine.
    Here is the class definition: .h
    Qt Code:
    1. #ifndef STATIONCARD_H
    2. #define STATIONCARD_H
    3.  
    4. #include <QLabel>
    5. #include <QGroupBox>
    6. #include <QLayout>
    7.  
    8. class StationCard : public QGroupBox{
    9. public:
    10. StationCard();
    11. QLabel *propLabel;
    12. int index;
    13. bool on;
    14.  
    15. signals:
    16. void toggled(int index, bool on);
    17.  
    18. private:
    19.  
    20. };
    21.  
    22. #endif // STATIONCARD_H
    To copy to clipboard, switch view to plain text mode 
    and .cpp
    Qt Code:
    1. #include "stationcard.h"
    2.  
    3. StationCard::StationCard(){
    4. QHBoxLayout *layout = new QHBoxLayout;
    5. propLabel = new QLabel();
    6. layout->addWidget(propLabel, 10, Qt::AlignRight);
    7. setLayout(layout);
    8.  
    9. on = isChecked();
    10. }
    To copy to clipboard, switch view to plain text mode 
    The connection is done in my main window when the card is initiated:
    Qt Code:
    1. StationVector.resize(8);
    2. int k = 0;
    3. for(int i = 0; i < 2; ++i){
    4. for(int j = 0; j < 4; ++j){
    5. StationVector[k] = new StationCard;
    6. StationVector[k]->index = k;
    7. QObject::connect(StationVector[k], SIGNAL(toggled(int, bool)), this, SLOT(on_stationCard_toggled(int, bool)));
    8. ui->cardLayout->addWidget(StationVector[k], i, j);
    9. k++;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    When I run it I get eight times
    Qt Code:
    1. QObject::connect: No such signal QGroupBox::toggled(int, bool)
    2. QObject::connect: (receiver name: 'MainWindow')
    To copy to clipboard, switch view to plain text mode 
    Thanks for helping!
    Last edited by KeineAhnung; 30th April 2014 at 23:07.

  2. #2
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QObject::connect: No such signal QGroupBox::toggled(int, bool)

    I'm not 100% sure on this, but I think you're supposed to have "Q_OBJECT" at the top of your class.

  3. #3
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QObject::connect: No such signal QGroupBox::toggled(int, bool)

    I tried that but then I get an error during compiling:
    Qt Code:
    1. Undefined symbols for architecture x86_64:
    2. "vtable for StationCard", referenced from:
    3. StationCard::StationCard() in stationcard.o
    To copy to clipboard, switch view to plain text mode 
    I tried to look into that as well but could not find anything that helped and since Q_OBJECT is called in my main window I thought I do not need to call it a second time.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QObject::connect: No such signal QGroupBox::toggled(int, bool)

    The class declaration requires the Q_OBJECT macro, the header file should be listed in the PRO file HEADERS variable, and qmake should be re-run after making changes like this.

    BTW: The QCheckBox already has a toggled(bool) signal that is used when the group box is checkable. I don't know if this is useful to you or not.

  5. #5
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QObject::connect: No such signal QGroupBox::toggled(int, bool)

    I don't know if it matters, but it seems odd to me that StationCard doesn't have a parent.

    Is StationVector a list of StationCard pointers?

  6. #6
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QObject::connect: No such signal QGroupBox::toggled(int, bool)

    Quote Originally Posted by sulliwk06 View Post
    Is StationVector a list of StationCard pointers?
    StationVector is a QVector<StationCard>. I have my cards stored there and displayed in a QGridLayout. Since I did not use the * the cards should not be pointers, right?


    To re-run qmake did the trick. I thought Qt Creator would do that for me if needed.
    I now that there is a signal toggled(bool) but I have eight cards and need to know where the signal came from. I hoped that I could extend the functionality by using the same name but that would have been too easy =).
    Is it possible to link the original toggled(bool) signal to my new signal?

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QObject::connect: No such signal QGroupBox::toggled(int, bool)

    I thought Qt Creator would do that for me if needed.
    It will if you modify the PRO file itself but not if, for example, you modify a header that is already listed in the PRO file. The Makefile written by qmake does not contain a dependency between the Makefile and every HEADERS files.

Similar Threads

  1. toggled(bool) signal does not call my slot?
    By Asperamanca in forum Newbie
    Replies: 6
    Last Post: 22nd July 2010, 10:54
  2. QObject::connect: Connecting from COMPAT signal...
    By ricardo in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2009, 18:09
  3. QGroupBox and signal clicked(bool)
    By codebehind in forum Newbie
    Replies: 9
    Last Post: 30th August 2008, 22:09
  4. QObject::connect: No such signal
    By caseyong in forum Qt Programming
    Replies: 5
    Last Post: 19th February 2008, 08:23

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.