How to use QWebSocket, QTcpSocket globally across the application?
-
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).
-
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).
@Joel-Bodenmann
MyNetworkHandlercontainingQTcpSocketmember? Does it mean I can directly call it without using signals? -
@Joel-Bodenmann
MyNetworkHandlercontainingQTcpSocketmember? Does it mean I can directly call it without using signals?It really depends on your needs. Theoretically you can make
MyNetworkHandlerbecome a subclass ofQTcpSocketand just make it a singleton. If you need more flexibility thenMyNetworkHandlercan just have aQTcpSocketinstance as a private handler. In that case you can still add your own signals and slots and/or forward those fromQTcpSocketwhere applicable.