I'm using Qt 5.3 with MinGW 4.8.2 (due to client restrictions the Qt version cannot be upgraded).
Trying to connect a QTcpSocket with a lambda expression ends up in a compiler error.
I have imported <QTcpSocket> and my class inherits QObject publicly. The Q_OBJECT macro has also been added to the header file.
This is how I am trying to connect the socket to a lambda function:
void TCPRequests::handleClient() {
QTcpSocket* sock = serv -> nextPendingConnection();
connect(sock, &QTcpSocket::readyRead, [sock]()
{
// Do nothing
});
}
This compiles and works correctly on Qt 5.8 but not on 5.3 with MinGW 4.8.2.
I have also tried to do
connect(sock, &QTcpSocket::readyRead, this, [sock]() {...}); (note I am also passing this as the third argument), but it makes no difference.
The resulting errors are:
First:
D:\Documents\Development\X\TCPRequests.cpp:43: error: no matching function for call to 'TCPRequests::connect(QTcpSocket*&, void (QIODevice::*)(), TCPRequests::handleClient()::__lambda0)' });
Second:
D:\Documents\Development\X\TCPRequests.cpp:43: error: template argument for 'template static typename QtPrivate::QEnableIf<((int)(QtPrivate::FunctionPointer::ArgumentCount) >= 0), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer::Object*, Func1, Func2)' uses local type 'TCPRequests::handleClient()::__lambda0' });
Third:
D:\Documents\Development\X\TCPRequests.cpp:43: error: template argument for 'template static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer::Object*, Func1, Func2)' uses local type 'TCPRequests::handleClient()::__lambda0' });
Any help would be very appreciated!