Results 1 to 14 of 14

Thread: QT4.2.2 and QTcpSocket

  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default QT4.2.2 and QTcpSocket

    Hi ,

    I'm using QT4.2.2 and I can't use the QTcpSockets (QtNetwork) .
    What about you ?

    Here is my code :
    Qt Code:
    1. #include <QtGui>
    2. #include <QObject>
    3. #include <QTcpSocket>
    4. #include <QtNetwork/QTcpSocket>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9.  
    10. QTcpSocket socket = new QTcpSocket();
    11.  
    12. socket->connectToHost("imap.free.fr", 143);
    13.  
    14. if ( !(socket->waitForConnected(-1)) )
    15. {
    16. printf("Unable to connect To Imap Server!\n");
    17. return 0;
    18. }
    19. else printf("Connection OK\n");
    20.  
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    For me, this code produce the following error :
    Qt Code:
    1. error: base operand of '->' has non-pointer type 'QTcpSocket'
    To copy to clipboard, switch view to plain text mode 

    However, I would like to write a small application that will check new mails from an Intranet IMAP server. I wanted to use the libvmime library, but it's difficult to use on Windows 2000... So I need to make my own class to check the mails on the server (no need to display content, no need to send mails, ...).

    Do you know if I can produce a socket oriented solution ?
    So you know if I can implement a securised connection, like the IMAPs is ? (IMAP on SSL)

    Thanks

  2. #2
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT4.2.2 and QTcpSocket

    Quote Originally Posted by Nyphel View Post
    Qt Code:
    1. QTcpSocket socket = new QTcpSocket();
    To copy to clipboard, switch view to plain text mode 
    Try
    Qt Code:
    1. QTcpSocket *socket = new QTcpSocket();
    To copy to clipboard, switch view to plain text mode 

    ;-)

    Quote Originally Posted by Nyphel View Post
    Do you know if I can produce a socket oriented solution ?
    Sure, why shouldn't you? You might just have to reimplement the protocol...and that is probably not much fun.

    There is, if I remember correctly, a project currently going on in the kde project to create a small imap-email client....you might want to check how they do it...

    Quote Originally Posted by Nyphel View Post
    So you know if I can implement a securised connection, like the IMAPs is ? (IMAP on SSL)
    You would need an SSL socket for that. You can either write one yourself, using for example gnutls, or, in case you can affort it, there is the QtSslSocket solution for Qt commercial customers.

  3. #3
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT4.2.2 and QTcpSocket

    Ok, thanks a lot for your detailed answer !

    But, what do you mean by "there is the QtSslSocket solution for Qt commercial customers" ?
    The QtSslSocket can be used only with a commercial licence of Qt ?

    I know that I'm not able to create my own SSL Socket ...
    And I can't buy a commercial licence of Qt.

  4. #4
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT4.2.2 and QTcpSocket

    Quote Originally Posted by Nyphel View Post
    But, what do you mean by "there is the QtSslSocket solution for Qt commercial customers" ?
    The QtSslSocket can be used only with a commercial licence of Qt ?
    The Qt Solutions are addons made by Trolltech, some are available only to license holders. See this page.

    The QtSslSocket is (sadly) one of them. There is probably a reason behind it, but I do not know.

    Quote Originally Posted by Nyphel View Post
    I know that I'm not able to create my own SSL Socket ...
    And I can't buy a commercial licence of Qt.
    Well, I guess the best would be to first get the security-less version on the road, and worry about the ssl thing later... ;-)

  5. The following user says thank you to camel for this useful post:

    Nyphel (22nd February 2007)

  6. #5
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT4.2.2 and QTcpSocket

    Hello,

    I had several problems using the QTcpSocket, and I can't find examples of code that use the QTcpSocket in order to access a server with IMAP.

    Do you have a sample code, please ?
    Or, perhaps, do you know where to find more informations ?

    Thanks



    PS : The following code throws me stranges errors :
    - "undefined reference to _imp___ZN10QTcpSocketC1EP7QObject"
    - "undefined reference to _imp___ZN15QAbstractSocket13connectToHostERK7QString6QFlagsIN9QIODevice120OpenModeFlagEE"
    Qt Code:
    1. #include <QtGui>
    2. #include <QObject>
    3. #include <QtNetwork/QTcpSocket>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. QTcpSocket * socket = new QTcpSocket();
    9. socket->connectToHost("imap.free.fr", 143);
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT4.2.2 and QTcpSocket

    Quote Originally Posted by Nyphel View Post
    Hello,

    I had several problems using the QTcpSocket, and I can't find examples of code that use the QTcpSocket in order to access a server with IMAP.
    Do you have a sample code, please ?
    I have non for imap, but there are a lot if QTcpSocket examples in the Trolltech documentation.

    Or just google a bit. I found for example mailody, an KDE-Imap client.
    Or search via Google Codesearch.
    A simple search produced for example this file which seems to be an inbox checker for imap written in Qt.

    Just remember, if you let yourself inspire by other code...honor the license and do not copy code...unless allowed by the license of course :-)

    Quote Originally Posted by Nyphel View Post
    Or, perhaps, do you know where to find more informations ?
    On what? QTcpSocket? Best use the Trolltech docs ;-)
    IMAP? Check the RFC?

    Quote Originally Posted by Nyphel View Post
    PS : The following code throws me stranges errors :
    - "undefined reference to _imp___ZN10QTcpSocketC1EP7QObject"
    Do you use qmake?
    Add "QT += network" to you pro file. It looks as if the network lib is not linked to your app.

  8. The following user says thank you to camel for this useful post:

    Nyphel (22nd February 2007)

  9. #7
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT4.2.2 and QTcpSocket

    Thanks a lot !

    The "QT += network" doesn't make anything better
    Perhaps my Qt installation is bad... I'll try to see it.

    Google Code Search is too usefull !
    It's the first time I hear baout it, thanks !

    Sorry if I let think that I didn't search a lot, but my QtAssistant doesn't display me the file and I didn't know Google Code Search... So it was a bit difficult

  10. #8
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT4.2.2 and QTcpSocket

    Quote Originally Posted by Nyphel View Post
    Google Code Search is too usefull !
    It's the first time I hear baout it, thanks !
    That's why I mentioned it...how does this old proverb go...
    Give a man a fish, and he will eat for a day,
    Teach a man to fish, and he will eat for a lifetime.



    Regarding your linking problem, I sadly have no idea what it could be...probably someone else does though :-)

  11. #9
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QT4.2.2 and QTcpSocket

    I was able to compile the following code:
    Qt Code:
    1. #include <QTcpSocket>
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QTcpSocket * socket = new QTcpSocket();
    8. socket->connectToHost("imap.free.fr", 143);
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    With this pro file:
    Qt Code:
    1. ######################################################################
    2. # Automatically generated by qmake (2.01a) Fri Feb 23 09:05:34 2007
    3. ######################################################################
    4.  
    5. QT += network
    6. TEMPLATE = app
    7. TARGET =
    8. DEPENDPATH += .
    9. INCLUDEPATH += .
    10.  
    11. # Input
    12. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    mAx

  12. #10
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT4.2.2 and QTcpSocket

    Thanks, the error was that my "qpake -project" doesn't add "QT += network" to my .pro file.

    I don't know how to solve that problem, but now I know that I can use the Sockets

  13. #11
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT4.2.2 and QTcpSocket

    Quote Originally Posted by Nyphel View Post
    Thanks, the error was that my "qpake -project" doesn't add "QT += network" to my .pro file.

    I don't know how to solve that problem, but now I know that I can use the Sockets
    Well, you only use qmake -project once (at least that is what it is intendet for from what I gather), and from then on you simply modify the ".pro" file by hand.

    The project file that qmake return is just a very rudimentary thing, and the .pro syntax is not too hard :-)

  14. #12
    Join Date
    Jun 2006
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT4.2.2 and QTcpSocket

    From command-line:
    Qt Code:
    1. qmake -project "QT = core gui network"
    To copy to clipboard, switch view to plain text mode 

  15. #13
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT4.2.2 and QTcpSocket

    Quote Originally Posted by Nyphel View Post
    I know that I'm not able to create my own SSL Socket ...
    And I can't buy a commercial licence of Qt.
    Just a small update:
    You are in luck: Check out the snapshots of Qt 4.3:
    There you will find a QSslSocket ;-)

    For more info check this blog entry

  16. The following user says thank you to camel for this useful post:

    Nyphel (11th March 2007)

  17. #14
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT4.2.2 and QTcpSocket

    Nice !

    Thanks for the tip Camel

Similar Threads

  1. problem with QTcpSocket
    By SuperSonik in forum Qt Programming
    Replies: 8
    Last Post: 31st January 2007, 16:00
  2. Problems with QThread and QTcpSocket
    By cookiem in forum Qt Programming
    Replies: 6
    Last Post: 2nd November 2006, 08:25
  3. Problem with QTcpSocket and QDataStream
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 16th September 2006, 13:08
  4. QTcpSocket - How do I know when it is disconnected ?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 3rd April 2006, 21:05
  5. QTcpSocket disconnection problem
    By erdi in forum Qt Programming
    Replies: 4
    Last Post: 19th February 2006, 21:50

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.