Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QGamePad - Does not detect disconnection - Linux

QGamePad - Does not detect disconnection - Linux

Scheduled Pinned Locked Moved Unsolved Game Development
3 Posts 3 Posters 1.3k Views
  • 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.
  • C Offline
    C Offline
    Caipiblack
    wrote on last edited by Caipiblack
    #1

    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)
                break;
        }
    
        n /= sizeof(::input_event);
    
        for (int i = 0; i < n; ++i)
            processInputEvent(&buffer[i]);
    
        return;
    
    err:
        if (!events) {
            qWarning("Gamepad: Got EOF from input device");
            return;
        } 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;
                    QT_CLOSE(m_fd);
                    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 ?

    aha_1980A 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should add your new findings to the bug report.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Caipiblack

        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)
                    break;
            }
        
            n /= sizeof(::input_event);
        
            for (int i = 0; i < n; ++i)
                processInputEvent(&buffer[i]);
        
            return;
        
        err:
            if (!events) {
                qWarning("Gamepad: Got EOF from input device");
                return;
            } 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;
                        QT_CLOSE(m_fd);
                        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 ?

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by aha_1980
        #3

        @Caipiblack

        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.

        Regards

        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).

        Qt has to stay free or it will die.

        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