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. QSerialPort handle on Windows
Forum Update on Monday, May 27th 2025

QSerialPort handle on Windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
serial portwindowsnative code
4 Posts 4 Posters 2.2k 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.
  • M Offline
    M Offline
    Morix Dev
    wrote on last edited by
    #1

    Hi. I've a problem trying to use QSerialPort's handle() method under Windows OS.

    I'd like to open a QSerialPort and then grab its handle for performing some operations on the port using the native Windows API (I need to do that because I have to obey some requests from a third-party library).

    Unfortunately, when I try to write some data on the Windows HANDLE returned by QSerialPort's handle() method then I have no effects: no data are being actually written on the port.

    Under Linux everything is fine, instead: writing data on the QSerialPort's handle() using the native API succeeds.

    Why on Windows it is not working? Any idea?

    Thanks,
    /Morix

    /Morix

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

      Hi,

      Maybe a silly question but did you check that you get a valid handle ?

      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
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on last edited by
        #3

        I don't sure that it is correct to do I/O (ReadFile/WriteFile) to QSerialPort using handle(). In this case you do not need then QSerialPort at all!!!

        1. QSerialPort opens device in overlapped mode, so, maybe it is reason, or you do ReadFile/WriteFile wrong.
        2. QSerialPort "listen" any I/O events on HANDLE with IOCP and process it automatically, so, maybe it is reason.
        3. Maybe something else.

        QSerialPort::handle() it is possible to use to change any other features with DeviceIoControl (e.g. timeouts, speed and so on), but I don't think, that ReadFile/WriteFile is possible... Please use QSerialPort::handle() on your own risk. :)

        1 Reply Last reply
        1
        • R Offline
          R Offline
          Rondog
          wrote on last edited by
          #4

          The overlapped mode is the problem. If you only have a handle then ReadFile / WriteFile will fail if you don't include the overlapped structure in the call. It was opened with the OVERLAPPED flag so this parameter cannot be NULL.

          What exactly are you trying to do? Maybe there is another way.

          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