QGamePad - Does not detect disconnection - Linux

  • Dear guy's

    The 11 November 2016 I have reported a problem with QGamePad on Linux (bug report)

    Currently (in 2018) it is still not fixed.

    The problem:
    With the backend "evdev" when the gamepad is disconnected the module doesn't process the event from the driver!

    It's a real problem because I have to control a heavy robot and it can be dangerous if the remote controller is disconnected because I have no ways to detect it using QGamePad: Nothing is updated on the module when it happens !

    The problem is in qevdevgamepadbackend.cpp the signal deviceRemoved() is not emit!. But if you see in readData(), this signal can be emit ...

    void QEvdevGamepadDevice::readData()
        input_event buffer[32];
        int events = 0, n = 0;
        for (; ;) {
            events = QT_READ(m_fd, reinterpret_cast<char*>(buffer) + n, sizeof(buffer) - n);
            if (events <= 0)
                goto err;
            n += events;
            if (n % sizeof(::input_event) == 0)
        n /= sizeof(::input_event);
        for (int i = 0; i < n; ++i)
        if (!events) {
            qWarning("Gamepad: Got EOF from input device");
        } else if (events < 0) {
            if (errno != EINTR && errno != EAGAIN) {
                qErrnoWarning(errno, "Gamepad: Could not read from input device");
                if (errno == ENODEV) { // device got disconnected -> stop reading
                    delete m_notifier;
                    m_notifier = 0;
                    m_fd = -1;

    When the gamepad is disconnected, the message "Gamepad: Could not read from input device" appear.

    Maybe we just have to add "emit deviceRemoved()" but you need to pass a QString with the device name, maybe that's the reason why it's not finished since two years

    Can someone check it please ?

  • Lifetime Qt Champion


    You should add your new findings to the bug report.

  • Qt Champions 2018


    I don't see a signal deviceRemoved() in QtGamePad. The nearest one is connectedChanged(bool) but that looks indeed like a possible signal in this situation.

    Have you already tried to patch the code yourself? Due to the lack of a gamepad, I cannot test this myself.


    Edit: Ah, there is a deviceRemoved() signal in QEvdevGamepadBackend which is used within the backend only for housekeeping. What stays, the signal you need outside is connectChanged(bool).


Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.