Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to use QWebSocket, QTcpSocket globally across the application?
fmj02 last edited by
I need to send packets from other classes, should I register a slot in my QTcpSocket class like "send" connect it and emit from other classes? Or is there a better way? Can I just use singleton like:
Joel Bodenmann last edited by Joel Bodenmann
Usually you'd create a custom class like
MyNetworkHandlerthat then can be a singleton if you wish. That class with have the corresponding methods to send the data you need to send from the different parts of the application.
Of course there are other solutions as well - it really depends on your needs and the design of the existing parts of the application. The above is just a good, common approach (in my opinion).
fmj02 last edited by fmj02
QTcpSocketmember? Does it mean I can directly call it without using signals?
Joel Bodenmann last edited by
It really depends on your needs. Theoretically you can make
MyNetworkHandlerbecome a subclass of
QTcpSocketand just make it a singleton. If you need more flexibility then
MyNetworkHandlercan just have a
QTcpSocketinstance as a private handler. In that case you can still add your own signals and slots and/or forward those from