Results 1 to 2 of 2

Thread: Do QTcpSocket or QSslSocket automatically create thread for reading/writing?

  1. #1
    Join Date
    Jun 2017
    Posts
    3
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Do QTcpSocket or QSslSocket automatically create thread for reading/writing?

    Despite not using `std::thread` or `QThread` anywhere, still getting following problems:
    1. Always a runtime debug error log from Qt:
    QObject::connect: Cannot queue arguments of type 'QAbstractSocket::SocketError'
    (Make sure 'QAbstractSocket::SocketError' is registered using qRegisterMetaType().)
    2. Intermittent crash on `TcpSocket::flush()` method; I use this method to make sure that the TCP is written immediately; Now sometimes the app crashes exactly at this method with `SIGPIPE`

    Upon searching internet, found that people suggest that to fix 1st problem (i.e. the meta error), I need to register using qRegisterMetaType(), when we have multiple threads.
    Same multithreading is referred as a cause for the 2nd problem as well; see this and this.

    But I don't have more than 1 thread!
    My socket code looks like below:
    Qt Code:
    1. struct Socket : public QSslSocket
    2. {
    3. Q_OBJECT public:
    4.  
    5. void ConnectSlots ()
    6. {
    7. const auto connectionType = Qt::QueuedConnection;
    8. connect(this, SIGNAL(readyRead()), this, SLOT(ReceiveData()), connectionType);
    9. connect(this, SIGNAL(disconnected()), this, SLOT(Disconnected()), connectionType);
    10. connect(this, SIGNAL(error(QAbstractSocket::SocketError)),
    11. this, SLOT(Error(QAbstractSocket::SocketError)), connectionType);
    12. // ^^^^^^^ error comes whether I comment this or not
    13. }
    14.  
    15. public slots:
    16. void ReceiveData () { ... }
    17. void Disconnected () { ... }
    18. void Error () { ... }
    19. }
    To copy to clipboard, switch view to plain text mode 
    Question: Is Qt creating any internal thread by itself for read/write purpose? (I hope not). How to fix above 2 issues?

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

    Default Re: Do QTcpSocket or QSslSocket automatically create thread for reading/writing?

    Registering the enums is a must if you want them to be used with signal/slots.
    It has nothing to do with threads.
    Is Qt creating any internal thread by itself for read/write purpose? (I hope not)
    No, they don't.
    ==========================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.

Similar Threads

  1. Replies: 4
    Last Post: 18th April 2016, 07:05
  2. Replies: 4
    Last Post: 26th January 2016, 14:25
  3. Replies: 6
    Last Post: 22nd December 2011, 21:03
  4. QTcpSocket writing reading problem
    By Misenko in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2008, 07:27
  5. Replies: 6
    Last Post: 8th January 2007, 10:24

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.