samedi 4 juin 2016

How can I use Qt5 connect() on a slot with default parameters

I have some code that looks something like this:

class MyClass : public QObject
{
    Q_OBJECT

signals:
    void SetValue(float value);

public slots:
    void OnSetValue(float value, bool fromDatabase = false);
}

Connect(this, SIGNAL(SetValue(float)), this, SLOT(OnSetValue(float)));

This works fine but I want to take advantage of Qt5's new signal/slot syntax (and remove the macros). If I change the connect() to this:

connect(this, &MyClass::SetValue, this, &MyClass::OnSetValue);

I get (in Visual Studio 2013):

error C2338: The slot requires more arguments than the signal provides

I could create an intermediary function that calls OnSetValue() and allows the default parameters to be set but that seems like a waste of code. What's a better way of solving this?

Aucun commentaire:

Enregistrer un commentaire