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. Use tcp connection like Sql Database
QtWS25 Last Chance

Use tcp connection like Sql Database

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtcpsockettcpqsqldatabaseqsqlqueryqtcpserver
5 Posts 3 Posters 522 Views
  • 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.
  • N Offline
    N Offline
    Narutoblaze
    wrote on 16 Nov 2023, 10:21 last edited by Narutoblaze
    #1

    I want use tcp connection like i am using QSqlDatabase.

    I connect to my SQL database like this :

    QSqlDatabase sql = QSqlDatabase::addDatabase("QSQL", "UI-Connection");
    sql.setHostName(127.168.1);
    

    And i can use this connection somewhere else like this :

    QSqlDatabase sql = QSqlDatabase::database("UI-Connection");
    

    Can i do something like this with tcp ?

    QTcpSocket soc = QTcpSocket ();
    
    J 1 Reply Last reply 16 Nov 2023, 10:24
    0
    • N Narutoblaze
      16 Nov 2023, 10:21

      I want use tcp connection like i am using QSqlDatabase.

      I connect to my SQL database like this :

      QSqlDatabase sql = QSqlDatabase::addDatabase("QSQL", "UI-Connection");
      sql.setHostName(127.168.1);
      

      And i can use this connection somewhere else like this :

      QSqlDatabase sql = QSqlDatabase::database("UI-Connection");
      

      Can i do something like this with tcp ?

      QTcpSocket soc = QTcpSocket ();
      
      J Offline
      J Offline
      JonB
      wrote on 16 Nov 2023, 10:24 last edited by JonB
      #2

      @Narutoblaze
      Yes, in the sense of having a TCP client. Look at the corresponding calls inherited from QAbstractSocket Class You specify a host and port to connect to, using connectToHost().

      N 1 Reply Last reply 16 Nov 2023, 10:39
      0
      • J JonB
        16 Nov 2023, 10:24

        @Narutoblaze
        Yes, in the sense of having a TCP client. Look at the corresponding calls inherited from QAbstractSocket Class You specify a host and port to connect to, using connectToHost().

        N Offline
        N Offline
        Narutoblaze
        wrote on 16 Nov 2023, 10:39 last edited by
        #3

        @JonB connectToHost() does not have like connection name as QSqlDatabase::addDatabase(const Qstring &type, const Qstring connectionName) have.

        If i was not clear enough sorry but i wanted to get the already connected connection like i can do in QSqlDatabase::database(const Qstring connectionName) giving the same connectionName i gave when QSqlDatabase::addDatabase()

        C J 2 Replies Last reply 16 Nov 2023, 10:59
        0
        • N Narutoblaze
          16 Nov 2023, 10:39

          @JonB connectToHost() does not have like connection name as QSqlDatabase::addDatabase(const Qstring &type, const Qstring connectionName) have.

          If i was not clear enough sorry but i wanted to get the already connected connection like i can do in QSqlDatabase::database(const Qstring connectionName) giving the same connectionName i gave when QSqlDatabase::addDatabase()

          C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 16 Nov 2023, 10:59 last edited by
          #4

          tbh I don't see any relationship between A QSqlDatabase connection and a QTcpSocket.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • N Narutoblaze
            16 Nov 2023, 10:39

            @JonB connectToHost() does not have like connection name as QSqlDatabase::addDatabase(const Qstring &type, const Qstring connectionName) have.

            If i was not clear enough sorry but i wanted to get the already connected connection like i can do in QSqlDatabase::database(const Qstring connectionName) giving the same connectionName i gave when QSqlDatabase::addDatabase()

            J Offline
            J Offline
            JonB
            wrote on 16 Nov 2023, 12:16 last edited by
            #5

            @Narutoblaze
            Then no you cannot, as you can see in the documentation for QTcpSocket/ QAbstractSocket. If there were a method which took a "connection name" you would see it documented.

            There is nothing to stop you writing your own code to store connections indexed by some "connection name" you choose, e.g. using a QMap Class.

            1 Reply Last reply
            1

            1/5

            16 Nov 2023, 10:21

            • Login

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