Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved if I unplug the device then also function QSerialPortInfo::availablePorts(); show serial port is avaiable. Is it other ways to find the devices is disconnected or not?

    General and Desktop
    3
    4
    971
    Loading More Posts
    • 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.
    • Y
      Yash001 last edited by

      I am using Qt 5.6.3. Here I found some realated document https://bugreports.qt.io/browse/QTBUG-50052. Inside the Document, find the unconnected port with help of error but I could not generate the error because port open,close, read, write handle into separate thread. current thread, just check the device is connected or not. if device is connected then data will be trasfer manually from GUI or receive into GUI.

      Device is not connected which is identify by comparing two list, already connected port and available port.

      auto availablePorts = QSerialPortInfo::availablePorts();

      if already connected port is not avaiable into avaiable port the device is disconnected and device show into GUI.

      auto error = QSerialPort::SerialPortError();
      qdebug() << "error" << error;

      here i am always getting QSerialPort::NoError.

      How can I solve this issue? or how can i Use QserialPortinfo from another verison of QT?

      aha_1980 1 Reply Last reply Reply Quote 0
      • aha_1980
        aha_1980 Lifetime Qt Champion @Yash001 last edited by

        Hi @Yash001,

        which platform are you using?

        QSerialPortInfo uses OS functions to detect the ports. So first we need to make sure your OS handles this properly.

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 2
        • Y
          Yash001 last edited by

          I am using OS window 10, Qt 5.6.3 with visual studio 2017.

          1 Reply Last reply Reply Quote 0
          • K
            kuzulis Qt Champions 2020 last edited by kuzulis

            On Windows, if you try to unplug an already opened serial port, then the QSPI may show that this serial port is available within some time, or, until you do not close it. It is completelly OS-specific issue, as Andre already said before.

            If you want to watch for a true serial port availability, then you need to implement own class-watcher, using WM_DEVICECHANGE on Windows, or, using udev's API on Linux (if you needs in).

            PS: Also I recomment update your Qt to latest.

            1 Reply Last reply Reply Quote 3
            • First post
              Last post