Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating sockets in qt
Qt 6.12 LTS is out! See what's new in the release blog

Creating sockets in qt

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.0k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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 this

    This 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);
    }
    @

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0

      • Login

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