jeudi 20 avril 2017

Connecting Signals to c++11 lamdas in QT5

I tried to connect a QDoubleSpinBox Signal to a c++11 lamda:

QObject::connect(sbox_roughness, &QDoubleSpinBox::valueChanged,
               [=]() { std::cout << "value changed" << std::endl; });

This is giving me:

error: no matching function for call to ‘Game::connect(QDoubleSpinBox*&, <unresolved overloaded function type>, Game::initGui()::<lambda()>)’
                [=]() { std::cout << "value changed" << std::endl; });
note:   no known conversion for argument 2 from ‘<unresolved overloaded function type>’ to ‘const char*’

I've tried this:

QObject::connect(sbox_roughness, static_cast<void (QDoubleSpinBox::*)(int)>(
                                   &QDoubleSpinBox::valueChanged),
               [=]() { std::cout << "value changed" << std::endl; }); 

giving me:

error: no matches converting function ‘valueChanged’ to type ‘void (class QDoubleSpinBox::*)(int)’
                                    &QDoubleSpinBox::valueChanged),

What am I missing here?

Aucun commentaire:

Enregistrer un commentaire