Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSerialPort permissions problem (No. Not the easy problem)
Qt 6.12 LTS is out! See what's new in the release blog

QSerialPort permissions problem (No. Not the easy problem)

Scheduled Pinned Locked Moved Unsolved General and Desktop
qserialport
17 Posts 6 Posters 7.4k Views 2 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #7

    I think they're created as QTemporaryFile so they should only be there when the program crashes - at least I would expect this.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    D 1 Reply Last reply
    2
    • Christian EhrlicherC Christian Ehrlicher

      I think they're created as QTemporaryFile so they should only be there when the program crashes - at least I would expect this.

      D Offline
      D Offline
      dhkaplan
      wrote on last edited by
      #8

      @Christian-Ehrlicher Apparently, the lock file is removed only if the QSeialPort::close() method is called, not if implicitly closed by (proper) program termination. I'd prefer it if this lock feature were optional.

      aha_1980A K 2 Replies Last reply
      0
      • D Offline
        D Offline
        dhkaplan
        wrote on last edited by
        #9

        OK I know how to deal with this now. Thanks for your help.

        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #10

          @dhkaplan said in QSerialPort permissions problem (No. Not the easy problem):

          Apparently, the lock file is removed only if the QSeialPort::close() method is called, not if implicitly closed by (proper) program termination. I'd prefer it if this lock feature were optional.

          And keep in mind that lock files implemented by the QSerialPort are specific to Qt, and NOT Linux system level..IOW, they only protect exclusive access in Qt applications.

          The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

          D 1 Reply Last reply
          1
          • Kent-DorfmanK Kent-Dorfman

            @dhkaplan said in QSerialPort permissions problem (No. Not the easy problem):

            Apparently, the lock file is removed only if the QSeialPort::close() method is called, not if implicitly closed by (proper) program termination. I'd prefer it if this lock feature were optional.

            And keep in mind that lock files implemented by the QSerialPort are specific to Qt, and NOT Linux system level..IOW, they only protect exclusive access in Qt applications.

            D Offline
            D Offline
            dhkaplan
            wrote on last edited by
            #11

            @Kent-Dorfman That's correct. No issues with non-Qt access to the serial ports.

            1 Reply Last reply
            0
            • D dhkaplan

              @Christian-Ehrlicher Apparently, the lock file is removed only if the QSeialPort::close() method is called, not if implicitly closed by (proper) program termination. I'd prefer it if this lock feature were optional.

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

              @dhkaplan

              Apparently, the lock file is removed only if the QSeialPort::close() method is called, not if implicitly closed by (proper) program termination.

              If that's the case, then it would be a bug. Because the design is as follows:

              The lock file is removed in QSerialPortPrivate::close(), which is called from QSerialPort::close() which is called from the destructor ~QSerialPort()

              Result: the lock file should be removed when the serial port object is removed.

              Regards

              Qt has to stay free or it will die.

              1 Reply Last reply
              2
              • Kent-DorfmanK Offline
                Kent-DorfmanK Offline
                Kent-Dorfman
                wrote on last edited by Kent-Dorfman
                #13

                Along the lines of serial port control in Linux, nothing says you HAVE to use the Qt classes for serial access. I usually just do POSIX programming in a separate thread with its own read loop and select() to read data when it's available...because I'm much familiar more with POSIX system programming. It's then not too hard to make the data available to the GUI thread via an IPC mechanism.

                The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

                aha_1980A 1 Reply Last reply
                0
                • Kent-DorfmanK Kent-Dorfman

                  Along the lines of serial port control in Linux, nothing says you HAVE to use the Qt classes for serial access. I usually just do POSIX programming in a separate thread with its own read loop and select() to read data when it's available...because I'm much familiar more with POSIX system programming. It's then not too hard to make the data available to the GUI thread via an IPC mechanism.

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

                  @Kent-Dorfman

                  I usually just do POSIX programming in a separate thread

                  Yeah, but that's not cross-platform ;)

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  0
                  • Kent-DorfmanK Offline
                    Kent-DorfmanK Offline
                    Kent-Dorfman
                    wrote on last edited by
                    #15

                    @aha_1980 said in QSerialPort permissions problem (No. Not the easy problem):

                    Yeah, but that's not cross-platform ;)

                    Op said he's working on Linux. Actually, I usually recommend manager daemons for access to I/O devices and use of IPC to communicate with them. By abstracting in that way the benefits are: much easier to unit test and validate, and the ability to trivially swap to different IO mechanisms. If your Serial daemon reships the data as a TCP stream then your clients only need to implement a TCP client handler...and guess what? Your serial data no longer needs to reside on the local machine. Then there is GPIO...NEVER give a userland client program direct access to GPIO. Always run it through a manager so that the client can only fiddle with the channels intended, and in a way that doesn't break things.

                    Anyway, more than enough comment to spawn a suitable flame war, so I digres.

                    The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

                    JonBJ 1 Reply Last reply
                    0
                    • D dhkaplan

                      @Christian-Ehrlicher Apparently, the lock file is removed only if the QSeialPort::close() method is called, not if implicitly closed by (proper) program termination. I'd prefer it if this lock feature were optional.

                      K Offline
                      K Offline
                      kuzulis
                      Qt Champions 2020
                      wrote on last edited by
                      #16

                      @dhkaplan said in QSerialPort permissions problem (No. Not the easy problem):

                      I'd prefer it if this lock feature were optional.

                      Lock files it is a common practicle. Besides, it gives same behavior on different platforms (as on Windows the serial ports opened only with exclusive access). And I can't imagine at all a situation when needs an access to the same serial port from different processes.

                      1 Reply Last reply
                      2
                      • Kent-DorfmanK Kent-Dorfman

                        @aha_1980 said in QSerialPort permissions problem (No. Not the easy problem):

                        Yeah, but that's not cross-platform ;)

                        Op said he's working on Linux. Actually, I usually recommend manager daemons for access to I/O devices and use of IPC to communicate with them. By abstracting in that way the benefits are: much easier to unit test and validate, and the ability to trivially swap to different IO mechanisms. If your Serial daemon reships the data as a TCP stream then your clients only need to implement a TCP client handler...and guess what? Your serial data no longer needs to reside on the local machine. Then there is GPIO...NEVER give a userland client program direct access to GPIO. Always run it through a manager so that the client can only fiddle with the channels intended, and in a way that doesn't break things.

                        Anyway, more than enough comment to spawn a suitable flame war, so I digres.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #17

                        @Kent-Dorfman
                        Out of curiosity, and not wanting to start a flame war, I'm slightly surprised that you ship I/O access out-of-process. It may well be convenient for debugging/testing, but for production? Then again I know nothing about hardware, so you may so that serial port top speed is slow it doesn't matter, I don't know....

                        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
                        • Unsolved