Results 1 to 2 of 2

Thread: Using Wsock32.lib with QT

  1. #1
    Join Date
    Apr 2012
    Posts
    1
    Platforms
    Windows

    Default Using Wsock32.lib with QT

    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.

    Qt Code:
    1. #ifndef CLIENT_S_
    2. #define CLIENT_S_
    3.  
    4. #include <string>
    5. #include <vector>
    6.  
    7. using namespace std;
    8.  
    9. class clientSession
    10. {
    11. private:
    12. SOCKET initSocket;
    13. int portNumber;
    14. string host;
    15. bool isSockInit;
    16.  
    17. public:
    18. clientSession(const int, const string);
    19. clientSession();
    20. string receiveText() const;
    21. void startConnection();
    22. bool receiveAck() const;
    23. bool sendRequest(const string) const;
    24. bool socketCheck() const;
    25. };
    26.  
    27. class messageSyntaxException
    28. {
    29. private:
    30. string error;
    31. public:
    32. messageSyntaxException(const string);
    33. const string what() const;
    34. };
    35.  
    36. class remoteHostException
    37. {
    38. private:
    39. string error;
    40. public:
    41. remoteHostException(const string);
    42. const string what() const;
    43. };
    44. #endif
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Using Wsock32.lib with QT

    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:
    Qt Code:
    1. LIBS += -lwsock32
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by wysota; 2nd April 2012 at 12:51.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.