Results 1 to 20 of 42

Thread: Problem by subclassing the QIODevice

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Problem by subclassing the QIODevice

    Quote Originally Posted by erqsor View Post
    but I really want to construct my API like the QTcpSocket and QUdpSocket (and other sockets)
    What other sockets?

    I don't want to limit my users
    That's what you're currently doing.
    Qt Code:
    1. qint64 QWsSocket::bytesAvailable() const
    2. {
    3. return buffer.size();
    4. }
    To copy to clipboard, switch view to plain text mode 
    That's incorrect. See docs for QIODevice::bytesAvailable().


    Qt Code:
    1. QByteArray QWsSocket::readAll()
    2. {
    3. qint64 sz = bytesAvailable();
    4. char * data = new char[sz];
    5. sz = readData(data, sz);
    6. return QByteArray(data, sz);
    7. }
    To copy to clipboard, switch view to plain text mode 
    That's incorrect. readAll() is not virtual.


    Qt Code:
    1. qint64 QWsSocket::read(char * data, qint64 maxSize)
    2. {
    3. return readData(data, maxSize);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Incorrect, read() is not virtual.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Jun 2010
    Posts
    34
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem by subclassing the QIODevice

    I don't want to limit my users
    That's what you're currently doing.
    I'm doing like Qt.

    That's incorrect. readAll() is not virtual.
    Incorrect, read() is not virtual.
    So what can I do ? QIODevice is useless if I cant use this functions...

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Problem by subclassing the QIODevice

    Quote Originally Posted by erqsor View Post
    I'm doing like Qt.
    What "Qt does" is not always correct. And you're not "doing like Qt". Qt tends to inherit QIODevice rather than its subclasses.

    So what can I do ? QIODevice is useless if I cant use this functions...
    Those methods are already implemented, you don't implement them yourself. Implement readData(), writeData(), bytesAvailable(), waitForBytesWritten(), waitForReadyRead(), possibly canReadLine() and readLineData(). QAbstractSocket uses an internal "socket engine" which does most of the work. If you want to implement your own subclass of QAbstractSocket class, you have to shadow all that because you don't have a working socket engine for your protocol underneath since your QWsSocket is not a real native socket. So you have to rewrite pretty much everything QAbstractSocket does (apart from close(), isSequential() and atEnd()).

    The more I look at the source code of QAbstractSocket the more I think this class was simply not meant to be subclassed outside Qt tree (not in this particular case but rather not meant to be subclassed at all). It has hardcoded support for UDP, TCP and SSL and doesn't allow hooking into the code with other implementations. QTcpSocket and QUdpSocket are simply stubs over QAbstractSocket which implements everything from both protocols itself (or actually delegates everything to a subclass of QAbstractSocketEngine such as QNativeSocketEngine).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QIODevice read() problem (reads more than maxSize)
    By m15ch4 in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2011, 11:09
  2. Subclassing QSortFilterProxyModel problem
    By e79ene in forum Newbie
    Replies: 2
    Last Post: 21st February 2011, 13:23
  3. Phonon: subclassing QIODevice
    By iDm.MuFFin123 in forum Qt Programming
    Replies: 0
    Last Post: 23rd May 2010, 13:29
  4. Subclassing QMainWindow problem
    By lerwys in forum Qt Programming
    Replies: 7
    Last Post: 28th April 2009, 08:40
  5. Problem with QTreeWidget after subclassing
    By steve918 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2006, 18:51

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.