Results 1 to 7 of 7

Thread: Qt causes conflicting function names

  1. #1
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt causes conflicting function names

    I've run into a problem where I have to create a socket on my own (not using the Qt sockets due to a bug) and have found that sockets on both *nix and windows have a connect() function that conflicts with Qt's connect() functions for signals and slots.

    I only need to use this connect function in one file. Is there a way to keep my program from picking up the Qt connect function instead of the socket connect function?

    Thanks,
    Paul

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt causes conflicting function names

    Use ::connect() to use the connect from BSD sockets. By the way, what bug are you talking about?

  3. #3
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt causes conflicting function names

    I'm writing a small app that uses the libssh2 library to make a simple ssh client. The library needs to have a socket created and then takes the socket descriptor and uses that.

    I was making a trial app to test the libraries functionallity to make sure that it would do what I needed it to do and was also seeing how I could integrate it with Qt. So I figured that I would use Qt's sockets to make my life easier. I found that on windows, my little test app creates the Qt socket just fine and the library can use it without problem (although the Qt socket doesn't seem to fire off signals when data is ready to be read...). But when running under linux, the library doesn't work. It bombs out when trying to exchange the encryption keys.

    Now there is a simple example that comes with the library that shows how to use to make a ssh connection. That example works just fine on both windows and linux. So at this point I'm trying to figure out exactly where the problem resides. I'm leaning towards this being a Qt socket bug problem since the lib example works on both OS when using their native socket creation methods. One other thing to test is to take their example and make the socket with a Qt socket and see if it still doesn't work.

    Paul

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt causes conflicting function names

    That's not really a bug. Qt sockets are not meant to be used this way, thus you should use BSD sockets directly. There is no benefit in using QTcpSocket there, so there is no point in using it.

  5. #5
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt causes conflicting function names

    Quote Originally Posted by wysota View Post
    ...There is no benefit in using QTcpSocket there, so there is no point in using it.
    I think I'm going to disagree with you there. I think that this is actually a prime example of one use of Qt sockets. I'd like to take advantage of Qt signals for when data arrives on the socket and is ready to be read instead of creating code to handle polling the socket every so often (windows) or using some other method (linux - select). With Qt, I can go without needing to create any methods to check for data, I can just link a simple signal/slot.

    According to the 4.3 doc on QAbstractSocket, they do mention that one of the uses if you need a socket is "Create a native socket descriptor, instantiate QAbstractSocket, and call setSocketDescriptor() to wrap the native socket."

    Might as well take advantage of Qt if I can to make my life easier! Course, with that little description, I realize that I'm going about it wrong. I should be natively creating the socket and then create a QAbstractSocket and give it the native socket descriptor. I'm currently doing it backwards. Hopefully some more experimentation tonight or tomorrow night will shed more light.

    Paul

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt causes conflicting function names

    Quote Originally Posted by thomaspu View Post
    I think I'm going to disagree with you there. I think that this is actually a prime example of one use of Qt sockets. I'd like to take advantage of Qt signals for when data arrives on the socket and is ready to be read instead of creating code to handle polling the socket every so often (windows) or using some other method (linux - select). With Qt, I can go without needing to create any methods to check for data, I can just link a simple signal/slot.
    But the library you are using is in control of the socket, not Qt, so you won't receive any signals. You can try using QSocketNotifier, but you don't need to use QTcpSocket with it - you can go directly for BSD sockets.


    According to the 4.3 doc on QAbstractSocket, they do mention that one of the uses if you need a socket is "Create a native socket descriptor, instantiate QAbstractSocket, and call setSocketDescriptor() to wrap the native socket."
    Yes, but that's when you want to use the socket with Qt interface and this is not the case here - you're using the ssh library instead. These two components simply won't interact, they rely on completely different mechanisms. Try using the socket notifier if all you want is to be informed that data is available in the socket (though you can achieve that with a plain ::select() call).

  7. The following user says thank you to wysota for this useful post:

    thomaspu (14th September 2007)

  8. #7
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt causes conflicting function names

    Hmm... well that makes sense why the Qt socket was never sending a notification signal when data was available on the socket. I was looking over the doc for the QSocketNotifier and that looks like it will do the trick. Now I just need to find out if that will effect the functionality on Windows: "The socket passed to QSocketNotifier will become non-blocking, even if it was created as a blocking socket".

    I hope that doesn't pose a problem. I'll have to look at the library to see if they set the socket to be a blocking socket. And if thats the case, well, just more code to write.

    Thanks for the response wysota, I think you might have just saved me a bunch of time scratching my head wondering why part of it doesn't work.

    Paul

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  2. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04
  3. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  4. Qt 4.1.4 plugin QPSQL
    By jcr in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd June 2006, 22:55
  5. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52

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
  •  
Qt is a trademark of The Qt Company.