How to use QWebSocket, QTcpSocket globally across the application?
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:
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).
QTcpSocketmember? Does it mean I can directly call it without using signals?
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