Results 1 to 8 of 8

Thread: how can i send QStringList index by index

  1. #1
    Join Date
    Jun 2021
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default how can i send QStringList index by index

    Hi
    i want send data from client to server index by index.
    but client packet all of index
    i put client code and server result, and sorry for my weak english
    Client Code:
    QStringList ql={"1","2","3","4"};
    foreach (QString tmp, ql) {
    socket->write(tmp.toUtf8()+"\n");
    socket->flush();
    }
    Server Result:
    "1\n2\n3\n4\n"

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how can i send QStringList index by index

    And what's the actual problem? The server received all the data or didn't it?

  3. #3
    Join Date
    Jun 2021
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how can i send QStringList index by index

    recived all data but client send all of data to one packet!
    I want client send QStringList One by One

    Server code:
    QStringList ql;
    void ::MainWindow readyRead()
    {
    QString buff=QString(qobject_cast<QTcpSocket*>(sender())->readAll());
    qDebug()<<buff;
    ql.append(buff);
    }

    And want server result like this:
    "1\n"
    "2\n"
    "3\n"
    "4\n"

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how can i send QStringList index by index

    tcp is stream-based... so I don't see what's wrong here.

  5. #5
    Join Date
    Jun 2021
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how can i send QStringList index by index

    actually i have a text file.client must send line by line of file to server and server must process line by line of data but client packet many of line and then send to server.
    as result server recive many of line and wrong process .
    this is my problem i hope you understand .thanks to you

  6. #6
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how can i send QStringList index by index

    Then split your received stream... tcp is a stream - no matter what you want or think. When you want a protocol you have to implement it by your own.

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

    Validimir_verekno (22nd June 2021)

  8. #7
    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: how can i send QStringList index by index

    Quote Originally Posted by Validimir_verekno View Post
    actually i have a text file.client must send line by line of file to server and server must process line by line of data but client packet many of line and then send to server.
    as result server recive many of line and wrong process .
    How does the client (sender) know when the server (receiver) is done processing the last line it received? This is the protocol that Christian Ehrlicher is talking about.

    The client is essentially a state machine that switches between:
    1. Send a line
    2. Wait for signal of completion from server (receive) then go to 1.

  9. #8
    Join Date
    Jun 2021
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how can i send QStringList index by index

    SOLVED
    thanks to "ChrisW67" & "ChristianEhrlicher"
    i find QStreamData : D
    QStreamData qsd(socket);
    qsd<<File.readLine();

Similar Threads

  1. Replies: 1
    Last Post: 4th February 2021, 11:58
  2. QNetworkinterface index
    By fruzzo in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2015, 11:26
  3. qstringlist index out of range at declaration!
    By fatecasino in forum Newbie
    Replies: 4
    Last Post: 30th April 2015, 17:33
  4. Readline from a particular index
    By giusepped in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2010, 21:58
  5. Get Row Index
    By wirasto in forum Qt Programming
    Replies: 4
    Last Post: 13th September 2009, 14:57

Tags for this Thread

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.