Qt No such slot using jump tables

63 Views Asked by At

I'm trying to create multiple QCheckBox without repeating code using a for. The problem is that for the connect I need a jump table array. The jump table declaration it's okey but then Qt don't find the slot.

Here is a simplified example:

QVBoxLayout* v = new QVBoxLayout;
m_jumpTable[0] = &Example::showZero;
m_jumpTable[1] = &Example::showOne;
m_jumpTable[2] = &Example::showTwo;
m_jumpTable[3] = &Example::showThree;
m_jumpTable[4] = &Example::showFour;

for (size_t i = 0; i < 5; ++i) {
    QCheckBox* check = new QCheckBox(tr(boxesText[i]));
    check->setChecked(boxesBools[i]);
    connect(check, SIGNAL(clicked(bool)), this, SLOT(m_jumpTable[i](bool)));
    v->addWidget(check);
}

PD: the m_jumpTable is a private variable from the object.

PD2: the index i it's not the problem I tested it with '0'.

1

There are 1 best solutions below

0
On BEST ANSWER

As per the comment, you will need to use the new signal/slot syntax for this so...

connect(check, SIGNAL(clicked(bool)), this, SLOT(m_jumpTable[i](bool)));

should be...

connect(check, &QCheckBox::clicked, this, m_jumpTable[i]);

(Assuming m_jumpTable[i] is of the correct type.)