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. Best practice for monitoring and reporting the writability of a QIODevice?
Forum Updated to NodeBB v4.3 + New Features

Best practice for monitoring and reporting the writability of a QIODevice?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.7k Views 1 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.
  • T Offline
    T Offline
    talmage
    wrote on last edited by
    #1

    Do we have a best practice for monitoring and reporting the writability of a QIODevice?

    I've written a QIODevice that encapsulates the datagram type (SOCK_DGRAM) of UNIX domain socket (AF_UNIX). It emits the readyWrite() signal whenever the socket is writable. A QSocketNotifier tells my QIODevice when the socket is writable. This happens often, so the QIODevice emits readyWrite() often. My application spends a lot of time responding to the signal by doing nothing because it has nothing to write. I'd like to find a less CPU-intensive way.

    Other QIODevices don't inform when they are writable. The "UNIX implementation of QLocalSocket":http://qt.gitorious.org/qt/qtbase/blobs/7eca53b51a2c7cae0b39fedb0b78205504bfd64b/src/network/socket/qlocalsocket_unix.cpp definitely doesn't.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rcari
      wrote on last edited by
      #2

      You should take a look at "QSocketNotifier":http://doc.qt.digia.com/qt/qsocketnotifier.html, pass it your socket file descriptor and use the enabled property. Whenever you receive the signal, you can disable the notifier so that you won't be notified again until you actually write something to it an re-enable it.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        talmage
        wrote on last edited by
        #3

        Thanks rcari. I am using QSocketNotifier. The slot I connected to its activate() signal disables the QSocketNotifier, emits the readyWrite() signal, then re-enables the QSocketNotifier. I could do as you suggest: not enable the QSocketNotifier. I suppose the same would apply to reading: just disable the QSocketNotifier and emit readyRead().

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

          Yes that's it, and only re-enable it once an actual read or an actual write occurs.
          You can easily do in the proper read/write methods.

          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