Use tcp connection like Sql Database
-
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 ();
-
@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, usingconnectToHost()
. -
@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()
-
tbh I don't see any relationship between A QSqlDatabase connection and a QTcpSocket.
-
@Narutoblaze
Then no you cannot, as you can see in the documentation forQTcpSocket
/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.