我会尝试编译这段代码。
头文件:
#ifndef SOCKETTEST_H
#define SOCKETTEST_H
#include <QObject>
#include <QSslSocket>
class SocketTest : public QObject
{
Q_OBJECT
public:
explicit SocketTest(QObject *parent = 0);
signals:
public slots:
void onError(QAbstractSocket::SocketError socketError);
};
#endif // SOCKETTEST_H
来源:
#include "sockettest.h"
SocketTest::SocketTest(QObject *parent) :
QObject(parent)
{
QSslSocket *socket = new QSslSocket(this);
connect(socket, &QSslSocket::error, this, &SocketTest::onError);
}
但是我遇到了这个错误:
sockettest.cpp:7: 错误:没有符合的函数调用 'SocketTest::connect(QSslSocket*&, , SocketTest* const, void (SocketTest::*)(QAbstractSocket::SocketError))'
我想使用新的connect()函数语法:
QMetaObject::Connection QObject::connect(const QObject * sender, PointerToMemberFunction signal, const QObject * receiver, PointerToMemberFunction method, Qt::ConnectionType type = Qt::AutoConnection) [static]
所以,我的问题是:如何使用connect函数的新语法将 QSslSocket::error()
信号连接到 SocketTest::onError()
槽?