Results 1 to 4 of 4

Thread: VS2008 build error for connect function

  1. #1
    Join Date
    Aug 2007
    Posts
    13
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default VS2008 build error for connect function

    I'm developing a client server application using winsock2.h functions of windows.
    But I have also some Gui's which are coded in QT 4.7 in the project.

    This part of the code is casue a build error:

    code :

    Qt Code:
    1. // Connect to server
    2. iResult= connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) );
    3. if (iResult == SOCKET_ERROR)
    4. {
    5. printf( "Failed to connect.\n" );
    6. WSACleanup();
    7. }
    To copy to clipboard, switch view to plain text mode 

    build error:

    1>.\client_thread.cpp(80) : error C2664: 'bool QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const' : cannot convert parameter 1 from 'SOCKET' to 'const QObject *'
    1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

    Compiler is assuming that the connect function is the function of QT (connect signal slot).

    How can I solve this ?
    Last edited by high_flyer; 11th February 2011 at 09:28. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: VS2008 build error for connect function

    How can I solve this ?
    By explicitly using the correct scope with '::'.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Aug 2007
    Posts
    13
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: VS2008 build error for connect function

    I changed the code as below:

    iResult= ::connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) );

    "You can tell the compiler to use the global identifier rather than the local identifier by prefixing the identifier with ::, the scope resolution operator."

    Ä°t's working now .But Im not sure that winsock connect function is global identifier and Qt connect function is not.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: VS2008 build error for connect function

    But Im not sure that winsock connect function is global identifier and Qt connect function is not.
    Check the docs, and you will be sure.
    Or go to the definition, and you will see which function is being called.
    Another way is to use defines (in such cases of conflicting names) like:
    #define qconnect ::connect
    Or just explicit scopes everywhere where such conflicts are probable, so the QObject connect is then QObejct::connect your socket connect is ::connect and all is well.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. error message in Ti SEH in VS2008 with QT 4.7.1 & QWT 5.1.1
    By stevethefirst in forum General Programming
    Replies: 4
    Last Post: 5th June 2012, 12:30
  2. help - need to build Qt libraries on 64Bit VS2008
    By caius9090 in forum Installation and Deployment
    Replies: 2
    Last Post: 15th November 2010, 21:18
  3. Runtime error QtGui4.dll VS2008
    By mbisotto in forum Installation and Deployment
    Replies: 3
    Last Post: 20th October 2010, 19:52
  4. Compile Qt 4.6.2 with VS2008 - exception in release build, debug ok
    By LynneV in forum Installation and Deployment
    Replies: 0
    Last Post: 7th June 2010, 04:52
  5. LNK 2019 Error while compiling qt program in VS2008
    By mevkurray in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 7th February 2010, 00:29

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.