Results 1 to 4 of 4

Thread: Network Programming Error/Line Edit

  1. #1
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Network Programming Error/Line Edit

    Dear All,

    I have created a Application using Qt Network Class. I have created a SERVER and CLIENT. Here Client is sending the data to Server. In server after accepting the New connection, Server socket reads the Packet data from Client. After analysing it. It should send the data to another Page(Mulitple MainWindows) on the same Application of the Server. Here I'm able to see all Debug messages. In server after logging in, It takes to child window is there. Here Lineedit are declared. Here the Data should Appear after checking the start bit after ReadLine in the child Window.

    SERVER Code:
    Qt Code:
    1. {
    2. QHostAddress hAddr;
    3. hAddr.setAddress("192.168.64.55");
    4.  
    5. //server->listen(hAddr,1234);
    6. server->listen(QHostAddress::Any,1234);
    7.  
    8.  
    9. Client Side:
    10. qDebug("Listening to new connection");
    11. }
    12.  
    13. void TeamStatus::on_newconn()
    14. {
    15. socket=server->nextPendingConnection();
    16. if((socket->state()==QTcpSocket::ConnectedState))
    17. {
    18. qDebug("new connection1 established");
    19. }
    20. connect(socket,SIGNAL(readyRead()),this,SLOT(read_socket()));
    21. }
    22.  
    23. void TeamStatus::read_socket()
    24. {
    25. QByteArray buffer= socket->readLine();
    26.  
    27.  
    28.  
    29.  
    30. if(buffer.startsWith("1"))
    31. {
    32. qDebug()<<buffer;
    33. qDebug("Next Page");
    34. qDebug()<<buf;
    35. tempage.le1->setText(buf); //This the another page where Line Edit is declared as le1... TEAMPAGE is made object at TEAMSTATUS.H file as teampage
    36. }
    37.  
    38. if(buffer.startsWith("2"))
    39. {
    40. qDebug()<<buffer;
    41. qDebug("Next Page");
    42. qDebug()<<buf;
    43. tempage.le2->setText(buf); //This the another page where Line Edit is declared as le1... TEAMPAGE is made object at TEAMSTATUS.H file as teampage
    44. }
    To copy to clipboard, switch view to plain text mode 


    CLIENT CODE
    Qt Code:
    1. void TCPClient::write()
    2. QString Data="",Data1=this->le->text();
    3. CHAT="1";
    4. Data.append(CHAT);
    5. Data.append(Data1);
    6. socket->write(Data.toUtf8().constData());
    7. qDebug("Client Sent 1 to Server");
    8. socket->flush();
    9. }
    10. void TCPClient::write1()
    11. {
    12. QString Data="",Data1=this->le->text();
    13. CHAT="2";
    14. Data.append(CHAT);
    15. Data.append(Data1);
    16. socket->write(Data.toUtf8().constData());
    17. qDebug("Client Sent 2 to server");
    18. socket->flush();
    19. }
    To copy to clipboard, switch view to plain text mode 

    Please Help I'm Stuck up here I'm not getting the text at the Server Lineedits. In debug msgs in console we can see, but not on the Application Window.
    Last edited by Vivek1982; 11th November 2013 at 13:47. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Network Programming Error/Line Edit

    Check that you are actually seeing those two line edits, not two other line edits

    E.g. set some text before you start to listen. Do you see the text when no client is connected.

    Cheers,
    _

  3. #3
    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: Network Programming Error/Line Edit

    You are assuming that readyRead() will be called once for each complete 'line' from the sender. This will rarely be the case. You cannot assume the first character in a read is the first character of a line, that the last character is the end of a line, or that you have only parts of a single line.

    You must buffer what is received until you can find a complete line in the data and then process it. You must leave any unprocessed data in the buffer.

    It it also not clear that you are sending a line ending, e.g. CR and/or LF, that the receiver will be looking for when reading a line.
    Last edited by ChrisW67; 11th November 2013 at 20:15.

  4. #4
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Network Programming Error/Line Edit

    Ya.. I made listen() function Disable in the same page and set the TEXT as tempage.setText->("NAME"). After compilation, I saw the Text in the child window in the required/assigned place. After getting connected to server, or while sending or receiving from client. The data packet is not getting checked and pushing the data in the required Line edits.Any problem can be in the Server packets or its connection.

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  2. Network Raw Programming
    By havij000 in forum Qt Programming
    Replies: 6
    Last Post: 28th August 2013, 11:49
  3. Replies: 3
    Last Post: 26th August 2010, 08:57
  4. qt4 network programming
    By linuxqt in forum General Programming
    Replies: 3
    Last Post: 12th March 2009, 15:41
  5. Replies: 8
    Last Post: 15th May 2007, 09:21

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.