user3813692
user3813692

Reputation: 1

Qt does not know accept for socket programming

If I press a button, a network server should get started. But it seems the compiler does not know the right accept-function. This line:

sockConnection = accept(hSocket, &remoteAddr, &iRemoteAddrLen);

gets this error:

no matching function for call to 'NetConf::accept(SOCKET&, sockaddr_in*, socklen_t*)'

It appears that the accept-function is part of a Qt Object and not the socket one I would like to use. I read about including "socket.h" but cant find it on my system (Windows 7 - 64 bit, Qt library 4.8.6). Any suggestions?

Upvotes: 0

Views: 102

Answers (1)

TheDarkKnight
TheDarkKnight

Reputation: 27611

Qt is a framework that abstracts away the requirement for calling low level functions such as accept.

If you want a TCP-based network server, start with a QTcpServer class object and call its listen function

If you've connected a QObject's slot to the QTcpServer's newConnection signal, you'll be notified when a connection is made.

Once notified of a new connection, you then call nextPendingConnection which returns a QTcpSocket, which you can use to communicate with the client by using its available functions as described in the Qt docs for this class.

Upvotes: 2

Related Questions