diff --git a/src/corelib/kernel/qsocketnotifier.cpp b/src/corelib/kernel/qsocketnotifier.cpp index 0e360342e9..8070d70a92 100644 --- a/src/corelib/kernel/qsocketnotifier.cpp +++ b/src/corelib/kernel/qsocketnotifier.cpp @@ -235,20 +235,19 @@ QSocketNotifier::~QSocketNotifier() /*! \since 6.1 - Assigns the \a socket to this notifier. The \a enable argument is - passed to the setEnabled() function. + Assigns the \a socket to this notifier. + + \note The notifier will be disabled as a side effect and needs + to be re-enabled. \sa setEnabled(), isValid() */ -void QSocketNotifier::setSocket(qintptr socket, bool enable) +void QSocketNotifier::setSocket(qintptr socket) { Q_D(QSocketNotifier); - if (d->sockfd != QSocketDescriptor(socket)) { - setEnabled(false); - d->sockfd = socket; - } - setEnabled(enable); + setEnabled(false); + d->sockfd = socket; } /*! diff --git a/src/corelib/kernel/qsocketnotifier.h b/src/corelib/kernel/qsocketnotifier.h index fdf11961c3..cd7d531687 100644 --- a/src/corelib/kernel/qsocketnotifier.h +++ b/src/corelib/kernel/qsocketnotifier.h @@ -58,7 +58,7 @@ public: QSocketNotifier(qintptr socket, Type, QObject *parent = nullptr); ~QSocketNotifier(); - void setSocket(qintptr socket, bool enable = false); + void setSocket(qintptr socket); qintptr socket() const; Type type() const; diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp index 79ee7da5b6..13ec6a7982 100644 --- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp +++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp @@ -102,12 +102,12 @@ void tst_QSocketNotifier::constructing() notifier.setEnabled(true); QVERIFY(!notifier.isEnabled()); - notifier.setSocket(fd, true); + notifier.setSocket(fd); QVERIFY(notifier.isValid()); QCOMPARE(notifier.socket(), fd); - QVERIFY(notifier.isEnabled()); - notifier.setEnabled(false); QVERIFY(!notifier.isEnabled()); + notifier.setEnabled(true); + QVERIFY(notifier.isEnabled()); } // Test constructing with the notifications enabled by default. @@ -119,12 +119,12 @@ void tst_QSocketNotifier::constructing() QCOMPARE(notifier.type(), QSocketNotifier::Write); QVERIFY(notifier.isEnabled()); - notifier.setSocket(fd, false); + notifier.setSocket(fd); QVERIFY(!notifier.isEnabled()); notifier.setEnabled(true); QVERIFY(notifier.isEnabled()); - notifier.setSocket(-1, true); + notifier.setSocket(-1); QVERIFY(!notifier.isValid()); QCOMPARE(notifier.socket(), Q_INT64_C(-1)); QVERIFY(!notifier.isEnabled());