Results 1 to 7 of 7

Thread: Need help. can't append chars in QString

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Need help. can't append chars in QString

    Quote Originally Posted by AcerExtensa View Post
    I trying to append chars readed from http response which is writen with wininit module into QString. but the QString is stays 0 byte length.
    Weird. Maybe the buffer begins with '\0'? What does "qDebug() << QByteArray( szBuffer, dwNumberOfBytesRead )" output?

    And you shouldn't disregard dwNumberOfBytesRead, unless you like random crashes.


    Quote Originally Posted by lyuts View Post
    You are not using append correctly. QString's append receives "char*" as a paramete,r but not "char".
    But szBuffer is a char *.

  2. #2
    Join Date
    Jun 2008
    Location
    Germany/Belarus/Sweden
    Posts
    53
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Need help. can't append chars in QString

    Here what I get with qDebug:
    "y></SOAP-ENV:Envelope>
    "
    and here is original response copyed from Wireshark:
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:crmlogon" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:crmLoginResponse><return xsi:type="xsd:string">dsfsdfdfsdfsdfdsfsdfdsf</return></ns1:crmLoginResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
    here is the code:
    Qt Code:
    1. DWORD code = sizeof (DWORD), dwBytesWritten = sizeof (code);
    2. ::HttpQueryInfo(hResourceHandle, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &dwBytesWritten, NULL);
    3. qDebug() << "status code:" << code;
    4. DWORD baval = sizeof(DWORD);
    5. ::InternetQueryDataAvailable(hResourceHandle, &baval, NULL, NULL);
    6. qDebug() << "Bytes Available:" << baval;
    7.  
    8. char szBuffer[256];
    9. DWORD dwNumberOfBytesRead = 1;
    10. while(dwNumberOfBytesRead){
    11. if(::InternetReadFile(hResourceHandle, szBuffer, sizeof(szBuffer),&dwNumberOfBytesRead)){
    12. if(dwNumberOfBytesRead == 0) break;
    13. //qDebug() << QByteArray( szBuffer, dwNumberOfBytesRead );
    14. //szBuffer[dwNumberOfBytesRead] = 0;
    15.  
    16.  
    17. qDebug() << "BytesRead" << dwNumberOfBytesRead;
    18. str.append(szBuffer);
    19. /*
    20. for(int i= 0; i<= (int)dwNumberOfBytesRead; i++){
    21. str += QString(szBuffer[i]);
    22. }*/
    23. qDebug() << "current str.length()" << str.length();
    24. }
    25. else{ qDebug() << "error:" << GetLastError(); }
    26. }
    27.  
    28.  
    29. QFile *file = new QFile("log");
    30. file->open(QIODevice::WriteOnly);
    31. bbb.append(str);
    32. file->write(bbb);
    33. file->close();
    34.  
    35. }
    36. else{
    37. qDebug() << "dwErrorCode" << GetLastError();
    38. }
    39. qDebug() << "complete response" << str;
    40. qDebug() << "length" << str.length();
    To copy to clipboard, switch view to plain text mode 

    debug output:
    status code: 200
    Bytes Available: 535
    BytesRead 256
    current str.length() 258
    BytesRead 256
    current str.length() 516
    BytesRead 23
    current str.length() 774
    length 774
    data in file:
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:crmlogon" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC=Hµݢhttp://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:crmLoginResponse><return xsi:type="xsd:string">93b262066b4ec01dcafd26f7fb26 f53e</return></ns1:crmLoginResponse></SOAP-ENV:BodH޹µ></SOAP-ENV:Envelope>
    .org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:crmLoginResponse><return xsi:type="xsd:string">93b262066b4ec01dcafd26f7fb26 f53e</return></ns1:crmLoginResponse></SOAP-ENV:BodH݀µ
    µ - on place µ symbol is symbole like that [] filled with black color, don't know wtf is that

    absolute same result if str is QByteArray.

    any idea people?

Similar Threads

  1. easiest Way QString can do
    By baray98 in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2008, 20:49
  2. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  3. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55
  4. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10
  5. [SOLVED] Widget plugin ... how to ?
    By yellowmat in forum Newbie
    Replies: 10
    Last Post: 29th January 2006, 20:41

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.