Results 1 to 4 of 4

Thread: Writing custom QIODevice with 2 channels

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Writing custom QIODevice with 2 channels

    Umm...
    Based on your code, there is no need to sublcass QIODevice, since you are doing nothing that the current QTcpSockets are not doing (QTcpSocket is a QIODevice).
    You detector class can be a simple QObject, which basically managers the the reading and writing to your two sockets (which is basically what your code appears to be trying to do).
    Line 37 in your code simply is not needed and is doing nothing of value.
    This way you don't have to implement the virtuals of QIOdevice and you can mold your API as you need it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Aug 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: Writing custom QIODevice with 2 channels

    First of all thank you for your reply. Much appreciated.

    Quote Originally Posted by high_flyer View Post
    Based on your code, there is no need to subcass QIODevice, since you are doing nothing that the current QTcpSockets are not doing (QTcpSocket is a QIODevice). You detector class can be a simple QObject...
    I agree that looking at my code there is no need for that, but I do want to extend my custom object, so that I will be able to take advantage of many other funcionalities of QIODevice, like for example being able to use QDataStream, which in constructor takes QIODevice. Moreover I would like to make my application very easy to reuse, by just replacing my custom QIODevice object to any other QIODevice object when it would be necessary.

    Quote Originally Posted by high_flyer View Post
    Line 37 in your code simply is not needed and is doing nothing of value.
    Yes, for now I am not using it, however it is setting some variables (Readonly / Writeonly) which I can check later on, in for example read / write methods to made them work corectly.

    And one more thing, why QT made such a beautiful class as QIODevice with support for multichannel communication when as far as I know no other QT object that is inheriting from it is using those channels?
    Last edited by notfound404; 16th August 2017 at 08:27.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Writing custom QIODevice with 2 channels

    I agree that looking at my code there is no need for that, but I do want to extend my custom object, so that I will be able to take advantage of many other funcionalities of QIODevice, like for example being able to use QDataStream, which in constructor takes QIODevice. Moreover I would like to make my application very easy to reuse, by just replacing my custom QIODevice object to any other QIODevice object when it would be necessary.
    Again, you CAN take advantage of these features by calling them on your QTcpSocket.

    Yes, for now I am not using it, however it is setting some variables (Readonly / Writeonly) which I can check later on, in for example read / write methods to made them work corectly.

    And one more thing, why QT made such a beautiful class as QIODevice with support for multichannel communication when as far as I know no other QT object that is inheriting from it is using those channels?
    Its sound to me you do not fully understand what subclassing is used for.
    Qt offers QIODevice for people to be able to write new QIODevices and to have an "interface" class to all QIODevices that are already implemented by Qt, this is what OOP is all about.
    That means if you have a new type of hardware that needs different implementation of writing, reading etc, then you can implement it in a way that will conform to QIODevice and allow you to use it with other Qt QIODevice consumer classes.
    This is however NOT what you are doing.
    You are fully content with using the functionality offered by QTcpSocket. (Based on the posted code).
    You don't need a new low level implementation of the socket, you simply have a case where you need to coordinate between two sockets - that is NOT a new device, that is simply a manager class.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. The following user says thank you to high_flyer for this useful post:

    notfound404 (16th August 2017)

Similar Threads

  1. BLE Writing to Custom Characteristic
    By GeorgeIoak in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2017, 16:39
  2. Phonon - Custom QIODevice to support encrypted files
    By hunsrus in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2012, 11:40
  3. QImageReader with custom QIODevice implementation
    By psih128 in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2011, 03:39
  4. Haw many channels does a QPixmap have?
    By ricardo in forum Qt Programming
    Replies: 1
    Last Post: 19th July 2009, 16:39
  5. Replies: 1
    Last Post: 26th January 2007, 07:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.