Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QClipboard changed not emitted when a QLocalSocket abnormally disconnects

QClipboard changed not emitted when a QLocalSocket abnormally disconnects

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 650 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neewill
    wrote on last edited by
    #1

    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:

    1. Run the listener application
    2. copy something to check for correct console output
    3. start a Client instance, copy something else again, checking for correct output.
    4. ctrl+c the client app.
    5. 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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved