Signals and Slots, update from old to new nomenclature
-
Hello again,
After reading the documents, I induced that the equivalent for the next connection:connect(tc, SIGNAL(sigCelsiusChanged(int)), ui->lcdCels, SLOT(display(int)) );would be the next:
connect(tc, &tempconverter::sigCelsiusChanged, ui->lcdCels, &QLCDNumber::display);but the compiler says:
C:\Qt\5.10.1\msvc2015\include\QtCore\qobject.h:214: candidate function not viable: no known conversion from 'void (tempconverter::*)(int) __attribute__((thiscall))' to 'const char *' for 2nd argumentplease, what I did wrong?
Thanks in advancewhere tc is my own objetc, here below
*.h#ifndef TEMPCONVERTER_H #define TEMPCONVERTER_H #include <QObject> class tempconverter : public QObject { Q_OBJECT int m_tempCelsius; public: tempconverter(int tempCelsius = 0, QObject *parent = nullptr); //Getter Functions int getCelsius() const; int getFahrenheit() const; public slots: void setCelsius(int); void setFahrenheit(int); signals: void sigCelsiusChanged(int); void sigFahrenheitChanged(int); }; #endif // TEMPCONVERTER_H*.cpp
#include "tempconverter.h" tempconverter::tempconverter(int tempCelsius, QObject *parent) : QObject(parent) { m_tempCelsius = tempCelsius; } int tempconverter::getCelsius() const { return m_tempCelsius; } int tempconverter::getFahrenheit() const { return static_cast<int>((9.0/5.0) * m_tempCelsius + 32); } void tempconverter::setCelsius(int tempCelsius) { if (m_tempCelsius == tempCelsius) return; m_tempCelsius = tempCelsius; //emit change signal emit sigCelsiusChanged(m_tempCelsius); emit sigFahrenheitChanged(getFahrenheit()); } void tempconverter::setFahrenheit(int tempFahrenheit) { setCelsius(static_cast<int>(5.0/9.0*(tempFahrenheit - 32))); } -
The problem is that
QLCDNumber::displayis overloaded, you can use:connect(tc, &tempconverter::sigCelsiusChanged, ui->lcdCels, QOverload<int>::of(&QLCDNumber::display));See https://wiki.qt.io/New_Signal_Slot_Syntax#Overload for more infos
-
The problem is that
QLCDNumber::displayis overloaded, you can use:connect(tc, &tempconverter::sigCelsiusChanged, ui->lcdCels, QOverload<int>::of(&QLCDNumber::display));See https://wiki.qt.io/New_Signal_Slot_Syntax#Overload for more infos
-
@Josz See also https://doc.qt.io/qt-5/signalsandslots-syntaxes.html for a comparison between the old and new connection syntaxes.
-
@Josz See also https://doc.qt.io/qt-5/signalsandslots-syntaxes.html for a comparison between the old and new connection syntaxes.