QClipboard changed not emitted when a QLocalSocket abnormally disconnects
-
Pretty sure this is a Qt bug but posting here before I put it on the bug tracker.
Setup is 2 applications:
1 app listens for clipboard changes via QClipboard::changed(), it also runs a QLocalServer listening for client connections.
A second app connects to the clipboard listener application's local socket.
In the event that a client connected to the listener exits abnormally (crash, force close, ctrl+c console app etc), then the listener application sees this disconnect but strangely receives no further QClipboard::changed signals.
Created a greatly simplified example:
listener.pro:
@
QT += core gui network widgets
TARGET = listener
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
@listener.cpp
@
#include <QApplication>
#include <QLocalServer>
#include <QLocalSocket>
#include <QClipboard>
#include <QDebug>int main(int argc, char *argv[])
{
QApplication a(argc, argv);QObject::connect(QApplication::clipboard(), &QClipboard::changed, [] () {
qDebug() << "clipboard changed!";
});QLocalServer* server = new QLocalServer();
QObject::connect(server, &QLocalServer::newConnection, [server] () {
qDebug() << "New Connection";QObject::connect(server->nextPendingConnection(), &QLocalSocket::disconnected, [] () { qDebug() << "Client disconnected"; });
});
server->listen("strange_behaviour");
return a.exec();
}
@client.pro
@
QT += core gui network widgets
TARGET = client
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
@client.cpp
@
#include <QApplication>
#include <QLocalSocket>
#include <QDebug>int main(int argc, char *argv[])
{
QApplication a(argc, argv);QLocalSocket* socket = new QLocalSocket();
socket->connectToServer("strange_behaviour");
return a.exec();
}
@Steps:
- Run the listener application
- copy something to check for correct console output
- start a Client instance, copy something else again, checking for correct output.
- ctrl+c the client app.
- copy again, no console output emitted.
Any ideas what may cause this? Any suggested workarounds?
I also tried using TcpSockets/Server instead, observed the same behaviour.
Under my main project, if the client app disconnects normally, calling disconnectFromServer then the listener application will continue to receive QClipboard::changed signals.
Seen on Windows 7, 32bit, Qt5.3, MSVC 2013 compiler.