QLocalSocket - deprecate ambiguous 'error' overloads
QLocalSocket::error is overloaded as a signal and an accessor (for the error reported by the signal). This means connecting to the signal using a pointer to member function would require ambiguity resolution. We deprecate the old accessor (to be removed in Qt 6) and introduce a new one - 'socketError'. [ChangeLog][Deprecation Notice] QLocalSocket::error() (the getter) is deprecated; superseded by socketError(). Task-number: QTBUG-80369 Change-Id: Iab346f7b4cd1024dee9e5ef71b4b7e09f6d95b12 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
94b3dd77f2
commit
0de6c26ac1
@ -220,11 +220,25 @@ QT_BEGIN_NAMESPACE
|
|||||||
/*!
|
/*!
|
||||||
\fn QLocalSocket::LocalSocketError QLocalSocket::error() const
|
\fn QLocalSocket::LocalSocketError QLocalSocket::error() const
|
||||||
|
|
||||||
|
\deprecated
|
||||||
|
|
||||||
|
Use socketError() instead.
|
||||||
|
|
||||||
|
Returns the type of error that last occurred.
|
||||||
|
|
||||||
|
\sa state(), errorString(), socketError()
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QLocalSocket::LocalSocketError QLocalSocket::socketError() const
|
||||||
|
\since 5.15
|
||||||
|
|
||||||
Returns the type of error that last occurred.
|
Returns the type of error that last occurred.
|
||||||
|
|
||||||
\sa state(), errorString()
|
\sa state(), errorString()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool QLocalSocket::isValid() const
|
\fn bool QLocalSocket::isValid() const
|
||||||
|
|
||||||
@ -272,7 +286,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
Waits until the socket is connected, up to \a msecs milliseconds. If the
|
Waits until the socket is connected, up to \a msecs milliseconds. If the
|
||||||
connection has been established, this function returns \c true; otherwise
|
connection has been established, this function returns \c true; otherwise
|
||||||
it returns \c false. In the case where it returns \c false, you can call
|
it returns \c false. In the case where it returns \c false, you can call
|
||||||
error() to determine the cause of the error.
|
socketError() to determine the cause of the error.
|
||||||
|
|
||||||
The following example waits up to one second for a connection
|
The following example waits up to one second for a connection
|
||||||
to be established:
|
to be established:
|
||||||
@ -291,7 +305,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
connection was successfully disconnected, this function returns \c true;
|
connection was successfully disconnected, this function returns \c true;
|
||||||
otherwise it returns \c false (if the operation timed out, if an error
|
otherwise it returns \c false (if the operation timed out, if an error
|
||||||
occurred, or if this QLocalSocket is already disconnected). In the case
|
occurred, or if this QLocalSocket is already disconnected). In the case
|
||||||
where it returns \c false, you can call error() to determine the cause of
|
where it returns \c false, you can call socketError() to determine the cause of
|
||||||
the error.
|
the error.
|
||||||
|
|
||||||
The following example waits up to one second for a connection
|
The following example waits up to one second for a connection
|
||||||
@ -337,7 +351,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
connections, you will have to register it with Q_DECLARE_METATYPE() and
|
connections, you will have to register it with Q_DECLARE_METATYPE() and
|
||||||
qRegisterMetaType().
|
qRegisterMetaType().
|
||||||
|
|
||||||
\sa error(), errorString(), {Creating Custom Qt Types}
|
\sa socketError(), errorString(), {Creating Custom Qt Types}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -446,7 +460,7 @@ QString QLocalSocket::fullServerName() const
|
|||||||
/*!
|
/*!
|
||||||
Returns the state of the socket.
|
Returns the state of the socket.
|
||||||
|
|
||||||
\sa error()
|
\sa socketError()
|
||||||
*/
|
*/
|
||||||
QLocalSocket::LocalSocketState QLocalSocket::state() const
|
QLocalSocket::LocalSocketState QLocalSocket::state() const
|
||||||
{
|
{
|
||||||
@ -466,7 +480,7 @@ bool QLocalSocket::isSequential() const
|
|||||||
|
|
||||||
The LocalServerError enumeration represents the errors that can occur.
|
The LocalServerError enumeration represents the errors that can occur.
|
||||||
The most recent error can be retrieved through a call to
|
The most recent error can be retrieved through a call to
|
||||||
\l QLocalSocket::error().
|
\l QLocalSocket::socketError().
|
||||||
|
|
||||||
\value ConnectionRefusedError The connection was refused by
|
\value ConnectionRefusedError The connection was refused by
|
||||||
the peer (or timed out).
|
the peer (or timed out).
|
||||||
|
@ -97,7 +97,12 @@ public:
|
|||||||
virtual bool canReadLine() const override;
|
virtual bool canReadLine() const override;
|
||||||
virtual bool open(OpenMode openMode = ReadWrite) override;
|
virtual bool open(OpenMode openMode = ReadWrite) override;
|
||||||
virtual void close() override;
|
virtual void close() override;
|
||||||
LocalSocketError error() const;
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
QT_DEPRECATED_X("Use socketError()") LocalSocketError error() const;
|
||||||
|
#endif // QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
|
||||||
|
LocalSocketError socketError() const;
|
||||||
bool flush();
|
bool flush();
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
qint64 readBufferSize() const;
|
qint64 readBufferSize() const;
|
||||||
|
@ -363,7 +363,14 @@ void QLocalSocket::disconnectFromServer()
|
|||||||
d->tcpSocket->disconnectFromHost();
|
d->tcpSocket->disconnectFromHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 15)
|
||||||
QLocalSocket::LocalSocketError QLocalSocket::error() const
|
QLocalSocket::LocalSocketError QLocalSocket::error() const
|
||||||
|
{
|
||||||
|
return socketError();
|
||||||
|
}
|
||||||
|
#endif // QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
|
||||||
|
QLocalSocket::LocalSocketError QLocalSocket::socketError() const
|
||||||
{
|
{
|
||||||
Q_D(const QLocalSocket);
|
Q_D(const QLocalSocket);
|
||||||
switch (d->tcpSocket->error()) {
|
switch (d->tcpSocket->error()) {
|
||||||
|
@ -461,7 +461,14 @@ void QLocalSocket::disconnectFromServer()
|
|||||||
d->unixSocket.disconnectFromHost();
|
d->unixSocket.disconnectFromHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 15)
|
||||||
QLocalSocket::LocalSocketError QLocalSocket::error() const
|
QLocalSocket::LocalSocketError QLocalSocket::error() const
|
||||||
|
{
|
||||||
|
return socketError();
|
||||||
|
}
|
||||||
|
#endif // QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
|
||||||
|
QLocalSocket::LocalSocketError QLocalSocket::socketError() const
|
||||||
{
|
{
|
||||||
Q_D(const QLocalSocket);
|
Q_D(const QLocalSocket);
|
||||||
switch (d->unixSocket.socketError()) {
|
switch (d->unixSocket.socketError()) {
|
||||||
|
@ -330,7 +330,14 @@ void QLocalSocket::disconnectFromServer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 15)
|
||||||
QLocalSocket::LocalSocketError QLocalSocket::error() const
|
QLocalSocket::LocalSocketError QLocalSocket::error() const
|
||||||
|
{
|
||||||
|
return socketError();
|
||||||
|
}
|
||||||
|
#endif // QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
|
||||||
|
QLocalSocket::LocalSocketError QLocalSocket::socketError() const
|
||||||
{
|
{
|
||||||
Q_D(const QLocalSocket);
|
Q_D(const QLocalSocket);
|
||||||
return d->error;
|
return d->error;
|
||||||
|
@ -65,8 +65,8 @@ bool runServer(int numberOfConnections)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
printf("server: data written\n");
|
printf("server: data written\n");
|
||||||
if (socket->error() != QLocalSocket::UnknownSocketError) {
|
if (socket->socketError() != QLocalSocket::UnknownSocketError) {
|
||||||
fprintf(stderr, "server: socket error %d\n", socket->error());
|
fprintf(stderr, "server: socket error %d\n", socket->socketError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,8 +83,8 @@ bool runClient()
|
|||||||
socket.connectToServer(serverName, QLocalSocket::ReadWrite);
|
socket.connectToServer(serverName, QLocalSocket::ReadWrite);
|
||||||
if (socket.waitForConnected())
|
if (socket.waitForConnected())
|
||||||
break;
|
break;
|
||||||
if (socket.error() == QLocalSocket::ServerNotFoundError
|
if (socket.socketError() == QLocalSocket::ServerNotFoundError
|
||||||
|| socket.error() == QLocalSocket::ConnectionRefusedError) {
|
|| socket.socketError() == QLocalSocket::ConnectionRefusedError) {
|
||||||
if (connectTimer.elapsed() > 5000) {
|
if (connectTimer.elapsed() > 5000) {
|
||||||
fprintf(stderr, "client: server not found or connection refused. Giving up.\n");
|
fprintf(stderr, "client: server not found or connection refused. Giving up.\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -195,7 +195,7 @@ private slots:
|
|||||||
void slotError(QLocalSocket::LocalSocketError newError)
|
void slotError(QLocalSocket::LocalSocketError newError)
|
||||||
{
|
{
|
||||||
QVERIFY(errorString() != QLatin1String("Unknown error"));
|
QVERIFY(errorString() != QLatin1String("Unknown error"));
|
||||||
QCOMPARE(error(), newError);
|
QCOMPARE(socketError(), newError);
|
||||||
}
|
}
|
||||||
void slotStateChanged(QLocalSocket::LocalSocketState newState)
|
void slotStateChanged(QLocalSocket::LocalSocketState newState)
|
||||||
{
|
{
|
||||||
@ -256,7 +256,7 @@ void tst_QLocalSocket::socket_basic()
|
|||||||
QCOMPARE(socket.canReadLine(), false);
|
QCOMPARE(socket.canReadLine(), false);
|
||||||
socket.close();
|
socket.close();
|
||||||
socket.disconnectFromServer();
|
socket.disconnectFromServer();
|
||||||
QCOMPARE(QLocalSocket::UnknownSocketError, socket.error());
|
QCOMPARE(QLocalSocket::UnknownSocketError, socket.socketError());
|
||||||
QVERIFY(!socket.errorString().isEmpty());
|
QVERIFY(!socket.errorString().isEmpty());
|
||||||
QCOMPARE(socket.flush(), false);
|
QCOMPARE(socket.flush(), false);
|
||||||
QCOMPARE(socket.isValid(), false);
|
QCOMPARE(socket.isValid(), false);
|
||||||
@ -375,13 +375,13 @@ void tst_QLocalSocket::listenAndConnect()
|
|||||||
QVERIFY(socket->waitForConnected());
|
QVERIFY(socket->waitForConnected());
|
||||||
QVERIFY(socket->isValid());
|
QVERIFY(socket->isValid());
|
||||||
QCOMPARE(socket->errorString(), QString("Unknown error"));
|
QCOMPARE(socket->errorString(), QString("Unknown error"));
|
||||||
QCOMPARE(socket->error(), QLocalSocket::UnknownSocketError);
|
QCOMPARE(socket->socketError(), QLocalSocket::UnknownSocketError);
|
||||||
QCOMPARE(socket->state(), QLocalSocket::ConnectedState);
|
QCOMPARE(socket->state(), QLocalSocket::ConnectedState);
|
||||||
//QVERIFY(socket->socketDescriptor() != -1);
|
//QVERIFY(socket->socketDescriptor() != -1);
|
||||||
QCOMPARE(spyError.count(), 0);
|
QCOMPARE(spyError.count(), 0);
|
||||||
} else {
|
} else {
|
||||||
QVERIFY(!socket->errorString().isEmpty());
|
QVERIFY(!socket->errorString().isEmpty());
|
||||||
QVERIFY(socket->error() != QLocalSocket::UnknownSocketError);
|
QVERIFY(socket->socketError() != QLocalSocket::UnknownSocketError);
|
||||||
QCOMPARE(socket->state(), QLocalSocket::UnconnectedState);
|
QCOMPARE(socket->state(), QLocalSocket::UnconnectedState);
|
||||||
//QCOMPARE(socket->socketDescriptor(), -1);
|
//QCOMPARE(socket->socketDescriptor(), -1);
|
||||||
QCOMPARE(qvariant_cast<QLocalSocket::LocalSocketError>(spyError.first()[0]),
|
QCOMPARE(qvariant_cast<QLocalSocket::LocalSocketError>(spyError.first()[0]),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user