Good day!

I understand the example of QT on working with modbus, I can not understand this line:

auto valueChanged = static_cast<void (QSpinBox::*)(int)> (&QSpinBox::valueChanged); 

There is a cast and a member of the class, but which one? and what does the sign mean?

    1 answer 1

    The QSpinBox class has two signals with the same name, but different signatures:

     void valueChanged(int i) void valueChanged(const QString &text) 

    Therefore, when writing, the compiler simply does not understand which pointer to which of the overloaded functions should be used:

     auto valueChanged = &QSpinBox::valueChanged; 

    In order to "prompt" to the compiler, this monstrous type function cast is used.

      static_cast<void (QSpinBox::*)(int)> (указатель на функцию); 

    Qt has the ability to use a shorter design for this:

     auto valueChanged = QOverload<int>::of(&QSpinBox::valueChanged); 

    The> symbol is part of the type specification for static_cast.

     static_cast<тип_функции>(указатель_на_функцию); 
    • Thank! At the expense of the sign> I later realized that this was a piece from a static cast! - Renovacio