Results 1 to 7 of 7

Thread: problem with QByteArray data !

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default Re: problem with QByteArray data !

    i' sorry .

    this is the original code :

    a part of simplechatclient.cpp :
    Qt Code:
    1. void SimpleChatClient::sendMessage()
    2. {
    3. // "<nick> message\n"
    4. socket->write("<" + nick->text().toLatin1() + "> " + message->text().toLatin1() + "\n");
    5. message->clear();
    6. }
    7.  
    8. void SimpleChatClient::receiveMessage()
    9. {
    10. // missing some checks for returns values for the sake of simplicity
    11. qint64 bytes = buffer->write(socket->readAll());
    12. // go back as many bytes as we just wrote so that it can be read
    13. buffer->seek(buffer->pos() - bytes);
    14. // read only full lines, line by line
    15. while (buffer->canReadLine())
    16. {
    17. QString line = buffer->readLine();
    18. chat->append(line.simplified());
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    a part of simplechatsever.cpp :

    Qt Code:
    1. void SimpleChatServer::receiveMessage()
    2. {
    3. QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
    4. QBuffer* buffer = buffers.value(socket);
    5.  
    6. // missing some checks for returns values for the sake of simplicity
    7. qint64 bytes = buffer->write(socket->readAll());
    8. // go back as many bytes as we just wrote so that it can be read
    9. buffer->seek(buffer->pos() - bytes);
    10. // read only full lines, line by line
    11. while (buffer->canReadLine())
    12. {
    13. QByteArray line = buffer->readLine();
    14. foreach (QTcpSocket* connection, connections)
    15. {
    16. connection->write(line);
    17. }
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    I had fix only at these methods And declare quint32 blockSize in the header file.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: problem with QByteArray data !

    Did you not try to debug your code before posting here?

    Eg. does sendMessage transmit a valid message?
    Which lines of receiveMessage are actually executed?

  3. #3
    Join Date
    Jan 2011
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default Re: problem with QByteArray data !

    i try to debug program and i get some error on "if (socket->bytesAvailable() < blockSize) return; ", i delete it from my source code then sendMessage and receiveMessage run on both server and client, but messenge data not receive, i have just known a little about it, but not mastered yet!

    help me ,i really need it :-(( thank in advance .

  4. #4
    Join Date
    Jan 2011
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default Re: problem with QByteArray data !

    UP ... help me :-(( i verry need it :-S

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

    Default Re: problem with QByteArray data !

    Check what blockSize contains after you stream data to it from the data stream.

    By the way, I think the code for the chat needs to be reviewed. Creating a data stream in a slot connected to readyRead() is really a bad idea.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QByteArray data manuplation.
    By nagabathula in forum Qt Programming
    Replies: 6
    Last Post: 4th December 2010, 16:08
  2. Replies: 3
    Last Post: 29th April 2010, 20:11
  3. inver data from QByteArray
    By aj2903 in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2010, 08:56
  4. QByteArray problem
    By Misenko in forum Qt Programming
    Replies: 17
    Last Post: 4th October 2008, 22:53
  5. QByteArray with network data
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2007, 18:53

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.