Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use QWebSocket, QTcpSocket globally across the application?
Forum Updated to NodeBB v4.3 + New Features

How to use QWebSocket, QTcpSocket globally across the application?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fmj02
    wrote on last edited by
    #1

    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:

    QTcpSocket g_tcpSocket;
    
    1 Reply Last reply
    0
    • Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on last edited by Joel Bodenmann
      #2

      Usually you'd create a custom class like MyNetworkHandler that 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).

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      F 1 Reply Last reply
      2
      • Joel BodenmannJ Joel Bodenmann

        Usually you'd create a custom class like MyNetworkHandler that 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).

        F Offline
        F Offline
        fmj02
        wrote on last edited by fmj02
        #3

        @Joel-Bodenmann MyNetworkHandler containing QTcpSocket member? Does it mean I can directly call it without using signals?

        Joel BodenmannJ 1 Reply Last reply
        0
        • F fmj02

          @Joel-Bodenmann MyNetworkHandler containing QTcpSocket member? Does it mean I can directly call it without using signals?

          Joel BodenmannJ Offline
          Joel BodenmannJ Offline
          Joel Bodenmann
          wrote on last edited by
          #4

          It really depends on your needs. Theoretically you can make MyNetworkHandler become a subclass of QTcpSocket and just make it a singleton. If you need more flexibility then MyNetworkHandler can just have a QTcpSocket instance as a private handler. In that case you can still add your own signals and slots and/or forward those from QTcpSocket where applicable.

          Industrial process automation software: https://simulton.com
          Embedded Graphics & GUI library: https://ugfx.io

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved