1 year ago

#229354

test-img

Jason C

Template deduction error binding QComboBox::currentIndexChanged to lambda

I am 100% sure that this is a not-enough-coffee problem, but I can't see what I'm doing wrong here. This code is attempting to connect a QComboBox's slot to a lambda (something I've done many times and yet...):

#include <QComboBox>

static void somewhere () {
    QComboBox *cb = ...;
    QObject::connect(cb, &QComboBox::currentIndexChanged, [cb](int){
    });
}

However, this fails to compile with a string of template deduction failures (full output here) ultimately resulting in:

error: no matching function for call to 'QObject::connect(QComboBox*&, 
    <unresolved overloaded function type>, somewhere(QComboBox*)::<lambda(int)>)'

This is Qt 5.15.2, compiled with gcc 8.1 (MinGW 8.1.0 64-bit), in C++17 mode.

QComboBox docs confirm the signal has an int parameter:

void QComboBox::currentIndexChanged(int index)

QObject docs confirm this form of connect exists as a static member:

connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)

What am I missing here... ?

c++

qt

lambda

compiler-errors

qobject

0 Answers

Your Answer

Accepted video resources