c++ - QString() vs sprintf() -



c++ - QString() vs sprintf() -

i have code in, there tcp connection between client , server. need send xml info server , receive response it. trying this:

char request[max]; sprintf(request, "<attestationrequest><majorversion>%d</majorversion><minorversion>%d</minorversion></attestationrequest>", major, minor); write(sockfd,request, length); while(recv(sockfd, response, max, 0) >= 0) { cout << "response " << response; //do something; }

but info received (expected response + request).

if seek fill info using qstring, info received proper.

qstring request = qstring("<attestationrequest>" "<majorversion>%1</majorversion>" "<minorversion>%2</minorversion>" "</attestationrequest>") .arg(major) .arg(minor)

the rest of code same both cases. receive more 11000 bytes of info when utilize sprintf, 9000 bytes in case of qstring. not able understand if missing something.

imo both solution bad. safer , improve utilize qxmlstreamwriter. manual manipulation on text in cases end wrong encoding or missing escape sequence or other xml format violation.

other problem didn't gave info how perform communication. highly probable there error causing problem.

c++ qt qstring

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -