QLocalSocket: Deprecate 'error' signal, use 'errorOccurred' instead
[ChangeLog][Deprecation Notice] QLocalSocket::error() (the signal) is deprecated; superseded by errorOccurred() Change-Id: I579c07564f5c470cf2867864755e0a26e6afce3b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
1c573ba47c
commit
c08b0cec2f
@ -83,8 +83,7 @@ Client::Client(QWidget *parent)
|
|||||||
this, &Client::requestNewFortune);
|
this, &Client::requestNewFortune);
|
||||||
connect(quitButton, &QPushButton::clicked, this, &Client::close);
|
connect(quitButton, &QPushButton::clicked, this, &Client::close);
|
||||||
connect(socket, &QLocalSocket::readyRead, this, &Client::readFortune);
|
connect(socket, &QLocalSocket::readyRead, this, &Client::readFortune);
|
||||||
connect(socket, QOverload<QLocalSocket::LocalSocketError>::of(&QLocalSocket::error),
|
connect(socket, &QLocalSocket::errorOccurred, this, &Client::displayError);
|
||||||
this, &Client::displayError);
|
|
||||||
|
|
||||||
QGridLayout *mainLayout = new QGridLayout(this);
|
QGridLayout *mainLayout = new QGridLayout(this);
|
||||||
mainLayout->addWidget(hostLabel, 0, 0);
|
mainLayout->addWidget(hostLabel, 0, 0);
|
||||||
|
@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
The socket is opened in the given \a openMode and first enters ConnectingState.
|
The socket is opened in the given \a openMode and first enters ConnectingState.
|
||||||
If a connection is established, QLocalSocket enters ConnectedState and emits connected().
|
If a connection is established, QLocalSocket enters ConnectedState and emits connected().
|
||||||
|
|
||||||
After calling this function, the socket can emit error() to signal that an error occurred.
|
After calling this function, the socket can emit errorOccurred() to signal that an error occurred.
|
||||||
|
|
||||||
\sa state(), serverName(), waitForConnected()
|
\sa state(), serverName(), waitForConnected()
|
||||||
*/
|
*/
|
||||||
@ -87,7 +87,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
Note that unlike in most other QIODevice subclasses, open() may not open the device directly.
|
Note that unlike in most other QIODevice subclasses, open() may not open the device directly.
|
||||||
The function return false if the socket was already connected or if the server to connect
|
The function return false if the socket was already connected or if the server to connect
|
||||||
to was not defined and true in any other case. The connected() or error() signals will be
|
to was not defined and true in any other case. The connected() or errorOccurred() signals will be
|
||||||
emitted once the device is actualy open (or the connection failed).
|
emitted once the device is actualy open (or the connection failed).
|
||||||
|
|
||||||
See connectToServer() for more details.
|
See connectToServer() for more details.
|
||||||
@ -329,6 +329,14 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn void QLocalSocket::error(QLocalSocket::LocalSocketError socketError)
|
\fn void QLocalSocket::error(QLocalSocket::LocalSocketError socketError)
|
||||||
|
\obsolete
|
||||||
|
|
||||||
|
Use errorOccurred() instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void QLocalSocket::errorOccurred(QLocalSocket::LocalSocketError socketError)
|
||||||
|
\since 5.15
|
||||||
|
|
||||||
This signal is emitted after an error occurred. The \a socketError
|
This signal is emitted after an error occurred. The \a socketError
|
||||||
parameter describes the type of error that occurred.
|
parameter describes the type of error that occurred.
|
||||||
@ -362,6 +370,9 @@ QLocalSocket::QLocalSocket(QObject * parent)
|
|||||||
{
|
{
|
||||||
Q_D(QLocalSocket);
|
Q_D(QLocalSocket);
|
||||||
d->init();
|
d->init();
|
||||||
|
|
||||||
|
// Support the deprecated error() signal:
|
||||||
|
connect(this, &QLocalSocket::errorOccurred, this, QOverload<QLocalSocket::LocalSocketError>::of(&QLocalSocket::error));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -389,7 +400,7 @@ bool QLocalSocket::open(OpenMode openMode)
|
|||||||
The socket is opened in the given \a openMode and first enters ConnectingState.
|
The socket is opened in the given \a openMode and first enters ConnectingState.
|
||||||
If a connection is established, QLocalSocket enters ConnectedState and emits connected().
|
If a connection is established, QLocalSocket enters ConnectedState and emits connected().
|
||||||
|
|
||||||
After calling this function, the socket can emit error() to signal that an error occurred.
|
After calling this function, the socket can emit errorOccurred() to signal that an error occurred.
|
||||||
|
|
||||||
\sa state(), serverName(), waitForConnected()
|
\sa state(), serverName(), waitForConnected()
|
||||||
*/
|
*/
|
||||||
|
@ -117,7 +117,11 @@ public:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void connected();
|
void connected();
|
||||||
void disconnected();
|
void disconnected();
|
||||||
|
#if QT_DEPRECATED_SINCE(5,15)
|
||||||
|
QT_DEPRECATED_X("Use QLocalSocket::errorOccurred(QLocalSocket::LocalSocketError) instead")
|
||||||
void error(QLocalSocket::LocalSocketError socketError);
|
void error(QLocalSocket::LocalSocketError socketError);
|
||||||
|
#endif
|
||||||
|
void errorOccurred(QLocalSocket::LocalSocketError socketError);
|
||||||
void stateChanged(QLocalSocket::LocalSocketState socketState);
|
void stateChanged(QLocalSocket::LocalSocketState socketState);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -95,7 +95,7 @@ void QLocalSocketPrivate::_q_error(QAbstractSocket::SocketError socketError)
|
|||||||
QLocalSocket::LocalSocketError error = (QLocalSocket::LocalSocketError)socketError;
|
QLocalSocket::LocalSocketError error = (QLocalSocket::LocalSocketError)socketError;
|
||||||
QString errorString = generateErrorString(error, function);
|
QString errorString = generateErrorString(error, function);
|
||||||
q->setErrorString(errorString);
|
q->setErrorString(errorString);
|
||||||
emit q->error(error);
|
emit q->errorOccurred(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
|
void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
|
||||||
@ -206,7 +206,7 @@ void QLocalSocketPrivate::setErrorAndEmit(QLocalSocket::LocalSocketError error,
|
|||||||
|
|
||||||
QString errorString = generateErrorString(error, function);
|
QString errorString = generateErrorString(error, function);
|
||||||
q->setErrorString(errorString);
|
q->setErrorString(errorString);
|
||||||
emit q->error(error);
|
emit q->errorOccurred(error);
|
||||||
|
|
||||||
// errors cause a disconnect
|
// errors cause a disconnect
|
||||||
tcpSocket->setSocketState(QAbstractSocket::UnconnectedState);
|
tcpSocket->setSocketState(QAbstractSocket::UnconnectedState);
|
||||||
@ -222,7 +222,7 @@ void QLocalSocket::connectToServer(OpenMode openMode)
|
|||||||
Q_D(QLocalSocket);
|
Q_D(QLocalSocket);
|
||||||
if (state() == ConnectedState || state() == ConnectingState) {
|
if (state() == ConnectedState || state() == ConnectingState) {
|
||||||
setErrorString(tr("Trying to connect while connection is in progress"));
|
setErrorString(tr("Trying to connect while connection is in progress"));
|
||||||
emit error(QLocalSocket::OperationError);
|
emit errorOccurred(QLocalSocket::OperationError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ void QLocalSocketPrivate::_q_error(QAbstractSocket::SocketError socketError)
|
|||||||
QLocalSocket::LocalSocketError error = (QLocalSocket::LocalSocketError)socketError;
|
QLocalSocket::LocalSocketError error = (QLocalSocket::LocalSocketError)socketError;
|
||||||
QString errorString = generateErrorString(error, function);
|
QString errorString = generateErrorString(error, function);
|
||||||
q->setErrorString(errorString);
|
q->setErrorString(errorString);
|
||||||
emit q->error(error);
|
emit q->errorOccurred(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
|
void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
|
||||||
@ -210,7 +210,7 @@ void QLocalSocketPrivate::setErrorAndEmit(QLocalSocket::LocalSocketError error,
|
|||||||
|
|
||||||
QString errorString = generateErrorString(error, function);
|
QString errorString = generateErrorString(error, function);
|
||||||
q->setErrorString(errorString);
|
q->setErrorString(errorString);
|
||||||
emit q->error(error);
|
emit q->errorOccurred(error);
|
||||||
|
|
||||||
// errors cause a disconnect
|
// errors cause a disconnect
|
||||||
unixSocket.setSocketState(QAbstractSocket::UnconnectedState);
|
unixSocket.setSocketState(QAbstractSocket::UnconnectedState);
|
||||||
@ -227,7 +227,7 @@ void QLocalSocket::connectToServer(OpenMode openMode)
|
|||||||
if (state() == ConnectedState || state() == ConnectingState) {
|
if (state() == ConnectedState || state() == ConnectingState) {
|
||||||
QString errorString = d->generateErrorString(QLocalSocket::OperationError, QLatin1String("QLocalSocket::connectToserver"));
|
QString errorString = d->generateErrorString(QLocalSocket::OperationError, QLatin1String("QLocalSocket::connectToserver"));
|
||||||
setErrorString(errorString);
|
setErrorString(errorString);
|
||||||
emit error(QLocalSocket::OperationError);
|
emit errorOccurred(QLocalSocket::OperationError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ void QLocalSocketPrivate::_q_winError(ulong windowsError, const QString &functio
|
|||||||
if (state == QLocalSocket::UnconnectedState && currentState != QLocalSocket::ConnectingState)
|
if (state == QLocalSocket::UnconnectedState && currentState != QLocalSocket::ConnectingState)
|
||||||
emit q->disconnected();
|
emit q->disconnected();
|
||||||
}
|
}
|
||||||
emit q->error(error);
|
emit q->errorOccurred(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
|
QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
|
||||||
@ -123,7 +123,7 @@ void QLocalSocket::connectToServer(OpenMode openMode)
|
|||||||
if (state() == ConnectedState || state() == ConnectingState) {
|
if (state() == ConnectedState || state() == ConnectingState) {
|
||||||
d->error = OperationError;
|
d->error = OperationError;
|
||||||
d->errorString = tr("Trying to connect while connection is in progress");
|
d->errorString = tr("Trying to connect while connection is in progress");
|
||||||
emit error(QLocalSocket::OperationError);
|
emit errorOccurred(QLocalSocket::OperationError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ void QLocalSocket::connectToServer(OpenMode openMode)
|
|||||||
d->error = ServerNotFoundError;
|
d->error = ServerNotFoundError;
|
||||||
d->errorString = tr("%1: Invalid name").arg(QLatin1String("QLocalSocket::connectToServer"));
|
d->errorString = tr("%1: Invalid name").arg(QLatin1String("QLocalSocket::connectToServer"));
|
||||||
d->state = UnconnectedState;
|
d->state = UnconnectedState;
|
||||||
emit error(d->error);
|
emit errorOccurred(d->error);
|
||||||
emit stateChanged(d->state);
|
emit stateChanged(d->state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ public:
|
|||||||
this, SLOT(slotConnected()));
|
this, SLOT(slotConnected()));
|
||||||
connect(this, SIGNAL(disconnected()),
|
connect(this, SIGNAL(disconnected()),
|
||||||
this, SLOT(slotDisconnected()));
|
this, SLOT(slotDisconnected()));
|
||||||
connect(this, SIGNAL(error(QLocalSocket::LocalSocketError)),
|
connect(this, SIGNAL(errorOccurred(QLocalSocket::LocalSocketError)),
|
||||||
this, SLOT(slotError(QLocalSocket::LocalSocketError)));
|
this, SLOT(slotError(QLocalSocket::LocalSocketError)));
|
||||||
connect(this, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)),
|
connect(this, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)),
|
||||||
this, SLOT(slotStateChanged(QLocalSocket::LocalSocketState)));
|
this, SLOT(slotStateChanged(QLocalSocket::LocalSocketState)));
|
||||||
@ -192,7 +192,7 @@ private slots:
|
|||||||
{
|
{
|
||||||
QCOMPARE(state(), QLocalSocket::UnconnectedState);
|
QCOMPARE(state(), QLocalSocket::UnconnectedState);
|
||||||
}
|
}
|
||||||
void slotError(QLocalSocket::LocalSocketError newError)
|
void slotErrorOccurred(QLocalSocket::LocalSocketError newError)
|
||||||
{
|
{
|
||||||
QVERIFY(errorString() != QLatin1String("Unknown error"));
|
QVERIFY(errorString() != QLatin1String("Unknown error"));
|
||||||
QCOMPARE(error(), newError);
|
QCOMPARE(error(), newError);
|
||||||
@ -244,7 +244,7 @@ void tst_QLocalSocket::socket_basic()
|
|||||||
LocalSocket socket;
|
LocalSocket socket;
|
||||||
QSignalSpy spyConnected(&socket, SIGNAL(connected()));
|
QSignalSpy spyConnected(&socket, SIGNAL(connected()));
|
||||||
QSignalSpy spyDisconnected(&socket, SIGNAL(disconnected()));
|
QSignalSpy spyDisconnected(&socket, SIGNAL(disconnected()));
|
||||||
QSignalSpy spyError(&socket, SIGNAL(error(QLocalSocket::LocalSocketError)));
|
QSignalSpy spyError(&socket, SIGNAL(errorOccurred(QLocalSocket::LocalSocketError)));
|
||||||
QSignalSpy spyStateChanged(&socket, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)));
|
QSignalSpy spyStateChanged(&socket, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)));
|
||||||
QSignalSpy spyReadyRead(&socket, SIGNAL(readyRead()));
|
QSignalSpy spyReadyRead(&socket, SIGNAL(readyRead()));
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ void tst_QLocalSocket::listenAndConnect()
|
|||||||
|
|
||||||
QSignalSpy spyConnected(socket, SIGNAL(connected()));
|
QSignalSpy spyConnected(socket, SIGNAL(connected()));
|
||||||
QSignalSpy spyDisconnected(socket, SIGNAL(disconnected()));
|
QSignalSpy spyDisconnected(socket, SIGNAL(disconnected()));
|
||||||
QSignalSpy spyError(socket, SIGNAL(error(QLocalSocket::LocalSocketError)));
|
QSignalSpy spyError(socket, SIGNAL(errorOccurred(QLocalSocket::LocalSocketError)));
|
||||||
QSignalSpy spyStateChanged(socket, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)));
|
QSignalSpy spyStateChanged(socket, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)));
|
||||||
QSignalSpy spyReadyRead(socket, SIGNAL(readyRead()));
|
QSignalSpy spyReadyRead(socket, SIGNAL(readyRead()));
|
||||||
|
|
||||||
@ -525,7 +525,7 @@ void tst_QLocalSocket::sendData()
|
|||||||
LocalSocket socket;
|
LocalSocket socket;
|
||||||
QSignalSpy spyConnected(&socket, SIGNAL(connected()));
|
QSignalSpy spyConnected(&socket, SIGNAL(connected()));
|
||||||
QSignalSpy spyDisconnected(&socket, SIGNAL(disconnected()));
|
QSignalSpy spyDisconnected(&socket, SIGNAL(disconnected()));
|
||||||
QSignalSpy spyError(&socket, SIGNAL(error(QLocalSocket::LocalSocketError)));
|
QSignalSpy spyError(&socket, SIGNAL(errorOccurred(QLocalSocket::LocalSocketError)));
|
||||||
QSignalSpy spyStateChanged(&socket, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)));
|
QSignalSpy spyStateChanged(&socket, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)));
|
||||||
QSignalSpy spyReadyRead(&socket, SIGNAL(readyRead()));
|
QSignalSpy spyReadyRead(&socket, SIGNAL(readyRead()));
|
||||||
|
|
||||||
@ -1104,7 +1104,7 @@ void tst_QLocalSocket::recycleClientSocket()
|
|||||||
QVERIFY(server.listen(serverName));
|
QVERIFY(server.listen(serverName));
|
||||||
QLocalSocket client;
|
QLocalSocket client;
|
||||||
QSignalSpy clientReadyReadSpy(&client, SIGNAL(readyRead()));
|
QSignalSpy clientReadyReadSpy(&client, SIGNAL(readyRead()));
|
||||||
QSignalSpy clientErrorSpy(&client, SIGNAL(error(QLocalSocket::LocalSocketError)));
|
QSignalSpy clientErrorSpy(&client, SIGNAL(errorOccurred(QLocalSocket::LocalSocketError)));
|
||||||
for (int i = 0; i < lines.count(); ++i) {
|
for (int i = 0; i < lines.count(); ++i) {
|
||||||
client.abort();
|
client.abort();
|
||||||
clientReadyReadSpy.clear();
|
clientReadyReadSpy.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user