vendredi 18 juin 2021

Qt No such slot using jump tables

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'.

Aucun commentaire:

Enregistrer un commentaire