PDA

View Full Version : Using Wsock32.lib with QT



ScottYK
2nd April 2012, 08:28
Hey I'm new to programming in QT and want to use a .h file from an existing project I created in Visual Studio that uses the winsock headers. In visual studio adding the wsock32.lib was easy through the project dependencies. How can I make it so my QT project is able to use the winsock headers. I know certain functions such as accept and connect may be already defined by QT specific headers and am wondering how to load and use the winsock headers. I have provided the .h file I am trying to use below and hope someone can help.



#ifndef CLIENT_S_
#define CLIENT_S_

#include <string>
#include <vector>

using namespace std;

class clientSession
{
private:
SOCKET initSocket;
int portNumber;
string host;
bool isSockInit;

public:
clientSession(const int, const string);
clientSession();
string receiveText() const;
void startConnection();
bool receiveAck() const;
bool sendRequest(const string) const;
bool socketCheck() const;
};

class messageSyntaxException
{
private:
string error;
public:
messageSyntaxException(const string);
const string what() const;
};

class remoteHostException
{
private:
string error;
public:
remoteHostException(const string);
const string what() const;
};
#endif

ChrisW67
2nd April 2012, 11:07
Qt is neither a language nor a compiler.

The question, "How do I use a third party library in a Qt project?", is solved with a the use of the LIBS variable in the pro file. Something like:


LIBS += -lwsock32

should be adequate. For the Microsoft or MingW compilers the headers and libraries are probably already in the respective default search paths. If not, you may need to adjust the INCLUDEPATH variable, and add a -L option to LIBS.

You might ask yourself why you are not using the networking infrastructure provided by Qt.