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>
public:
StationCard();
int index;
bool on;
signals:
void toggled(int index, bool on);
private:
};
#endif // STATIONCARD_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
To copy to clipboard, switch view to plain text mode
and .cpp
#include "stationcard.h"
StationCard::StationCard(){
layout->addWidget(propLabel, 10, Qt::AlignRight);
setLayout(layout);
on = isChecked();
}
#include "stationcard.h"
StationCard::StationCard(){
QHBoxLayout *layout = new QHBoxLayout;
propLabel = new QLabel();
layout->addWidget(propLabel, 10, Qt::AlignRight);
setLayout(layout);
on = isChecked();
}
To copy to clipboard, switch view to plain text mode
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++;
}
}
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++;
}
}
To copy to clipboard, switch view to plain text mode
When I run it I get eight times
QObject::connect: (receiver name
: 'MainWindow')
QObject::connect: No such signal QGroupBox::toggled(int, bool)
QObject::connect: (receiver name: 'MainWindow')
To copy to clipboard, switch view to plain text mode
Thanks for helping!
Bookmarks