PDA

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



KeineAhnung
30th April 2014, 21:13
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


#ifndef STATIONCARD_H
#define STATIONCARD_H

#include <QLabel>
#include <QGroupBox>
#include <QLayout>

class StationCard : public QGroupBox{
public:
StationCard();
QLabel *propLabel;
int index;
bool on;

signals:
void toggled(int index, bool on);

private:

};

#endif // STATIONCARD_H

and .cpp


#include "stationcard.h"

StationCard::StationCard(){
QHBoxLayout *layout = new QHBoxLayout;
propLabel = new QLabel();
layout->addWidget(propLabel, 10, Qt::AlignRight);
setLayout(layout);

on = isChecked();
}

The connection is done in my main window when the card is initiated:


StationVector.resize(8);
int k = 0;
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 4; ++j){
StationVector[k] = new StationCard;
StationVector[k]->index = k;
QObject::connect(StationVector[k], SIGNAL(toggled(int, bool)), this, SLOT(on_stationCard_toggled(int, bool)));
ui->cardLayout->addWidget(StationVector[k], i, j);
k++;
}
}

When I run it I get eight times


QObject::connect: No such signal QGroupBox::toggled(int, bool)
QObject::connect: (receiver name: 'MainWindow')

Thanks for helping!

sulliwk06
30th April 2014, 21:32
I'm not 100% sure on this, but I think you're supposed to have "Q_OBJECT" at the top of your class.

KeineAhnung
30th April 2014, 21:37
I tried that but then I get an error during compiling:


Undefined symbols for architecture x86_64:
"vtable for StationCard", referenced from:
StationCard::StationCard() in stationcard.o

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.

ChrisW67
30th April 2014, 21:48
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.

sulliwk06
30th April 2014, 21:51
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?

KeineAhnung
30th April 2014, 22:02
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?

ChrisW67
1st May 2014, 02:30
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.