Results 1 to 3 of 3

Thread: Very simple problem with QServerSocket and Qsocket

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    3
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Very simple problem with QServerSocket and Qsocket

    I tried doing my own implementation of these classes. Actually, I used the exact same code that is used in the simple network example in the Qt help files. Later on, I will have to change the newConnection function to do what I want it do, but for now, the only difference is that I want to us a different GUI, created with Qt designer, and I can't seem to get it work.

    Instead of having this class in a cpp file:

    Qt Code:
    1. class ServerInfo : public QVBox
    2. {
    3. Q_OBJECT
    4. public:
    5. ServerInfo()
    6. {
    7. SimpleServer *server = new SimpleServer( this );
    8.  
    9. QString itext = tr(
    10. "This is a small server example.\n"
    11. "Connect with the client now."
    12. );
    13. QLabel *lb = new QLabel( itext, this );
    14. lb->setAlignment( AlignHCenter );
    15. infoText = new QTextView( this );
    16. QPushButton *quit = new QPushButton( tr("Quit") , this );
    17.  
    18. connect( server, SIGNAL(newConnect(ClientSocket*)),
    19. SLOT(newConnect(ClientSocket*)) );
    20. connect( quit, SIGNAL(clicked()), qApp,
    21. SLOT(quit()) );
    22. }
    23.  
    24. ~ServerInfo()
    25. {
    26. }
    27.  
    28. private slots:
    29. void newConnect( ClientSocket *s )
    30. {
    31. infoText->append( tr("New connection\n") );
    32. connect( s, SIGNAL(logText(const QString&)),
    33. infoText, SLOT(append(const QString&)) );
    34. connect( s, SIGNAL(connectionClosed()),
    35. SLOT(connectionClosed()) );
    36. }
    37.  
    38. void connectionClosed()
    39. {
    40. infoText->append( tr("Client closed connection\n") );
    41. }
    42.  
    43. private:
    44. QTextView *infoText;
    45. };
    To copy to clipboard, switch view to plain text mode 


    I have this in a form.ui.h file. (infoText text browser was created in qt designer)

    Qt Code:
    1. #include "clientsocket.h"
    2. #include "server.h"
    3.  
    4. void Form1::init(){
    5. SimpleServer *server = new SimpleServer( this );
    6. connect( server, SIGNAL(newConnect(ClientSocket*)),
    7. SLOT(newConnect(ClientSocket*)) );
    8. }
    9.  
    10. void Form1::newConnect( ClientSocket *s ){
    11. infoText->append( tr("New connection\n") );
    12. connect( s, SIGNAL(logText(const QString&)),
    13. infoText, SLOT(append(const QString&)) );
    14. connect( s, SIGNAL(connectionClosed()),
    15. SLOT(connectionClosed()) );
    16. }
    17.  
    18. void Form1::connectionClosed(){
    19. infoText->append( tr("Client closed connection\n") );
    20. }
    To copy to clipboard, switch view to plain text mode 


    When I try to make, I get:

    Qt Code:
    1. form1.h:36: error: "ClientConnect" was not declared
    To copy to clipboard, switch view to plain text mode 

    as if it were an object and not a type. I'm sorry if this question sounds really stupid but I'm a beginner and believe me, I've tried all sorts of things to make it work.

  2. #2
    Join Date
    Nov 2006
    Posts
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Very simple problem with QServerSocket and Qsocket

    For me it is always easier to take a look at the generated from1.h file. Maybe Designer put something weird in the ui file. Can you post the part where the error occured?

    Just to make it clear: The first code quotation is a h-file!? The second one is a cpp-file!?
    Last edited by Elgerton; 3rd November 2006 at 08:56.

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

    Default Re: Very simple problem with QServerSocket and Qsocket

    Could you show us a part of code where ClientConnect is used? What is ClientConnect anyway?

Similar Threads

  1. Sending a image using QSocket & QServerSocket
    By machathu in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2006, 12:23

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.