Creating sockets in qt
-
Hi,
Myself trying to create a socket connection in qt.In the following code the connect () is getting confilicted with QObject::connect.How can i fix thisThis is the code snippet
@
int sock_Desc = 0;
if (proxy_port == 0)
{
proxy_port = 3773;
}
sock_Desc = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in server;
server.sin_addr.s_addr = inet_addr(127.0.0.1);
server.sin_family = AF_INET;
server.sin_port = htons(proxy_port);
connect(sock_Desc, (struct sockaddr *)&server, sizeof(server));
int rc = 0;
if ((option & 1) == 0)
{
if(send(sock_Desc, message, strlen(message), 0) < 0) {close(sock_Desc); } if ((option & 2) == 2) { rc = recv(sock_Desc, rcv_Msg, 512, 0); if (rc == 0) { close(sock_Desc); } if (rc < 0) { close(sock_Desc); } }
} else {
if(option & 2 == 2)
{
rc = system(message);
} }
}close(sock_Desc);
}
@ -
You do not give details, but I assume that your class is in one way or another derived from QObject. Probably it conflicts then with the "member function":http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#connect-3 or one of the static connects.
Rename it to something else. Certainly it is nice to have a socket's member function used to connect to something called connect, but that is not the best name as you see.
BTW: Please checkout the rules to "include code tags":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 otherwise your code is not really readable.
This time I have included them for you.