Hi,
Thanks for the reply.
THis is my first project as a developer. Requesting you for the one more clarification.
Here is the question.
By using this below 1st piece of code I can read both header and body of the xml file.
1. QString data = (QString) pReply->readAll();
and by using this 2nd piece of code I can read only body of the xml file
2. QString data = (QString) pReply->readRead();
Does this my understanding this concept is correct.?
Please Find the below piece of code I have written for to pass the xml using http . my intention is to pass only the received xml
body to the function decoder .
void Uploader::upload(QString xmlFilePath)
{
qDebug() << "Upload Starting";
QFileInfo fileInfo(xmlFilePath);
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart filePart;
filePart.setHeader(QNetworkRequest::ContentDisposi tionHeader, QVariant("HTTP/1.1 200 OK"));
filePart.setHeader(QNetworkRequest::ContentTypeHea der, QVariant("text/xml; charset=utf-8"));
QFile *file = new QFile(xmlFilePath);
if ( !file->exists() )
{
qDebug() << "File Does not exist";
}
file->open(QIODevice::ReadOnly);
filePart.setBodyDevice(file);
file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
multiPart->append(filePart);
QUrl url("http://google.com");
QNetworkRequest request(url);
pManager = new QNetworkAccessManager();
pReply = pManager->post(request, multiPart);
multiPart->setParent(pReply);
QObject::connect(pReply, SIGNAL(QNetworkReply::finished()),this, SLOT(Uploader::uploadFinished()));
uploadInProgress = true;
uploadtoDecoder();
}
/**
* @brief Uploader::uploadFinished
*/
void Uploader::uploadFinished()
{
QString data = (QString) pReply->readAll();
qDebug() << data;
qDebug() << "Upload finished";
uploadInProgress = false;
if ( pReply->error() > 0 )
{
qDebug() << "Error occured: " << pReply->error() << " : " << pReply->errorString();
}
else
{
qDebug() << "Upload success";
}
pReply->deleteLater();
}
/**
* @brief Uploader::uploadToDecoder
*/
void Uploader::uploadToDecoder()
{
/* I have doubt here only */
QString datafull = (QString) pReply->readAll(); \\for to read both header and body
qDebug() << data;
QString data = (QString) pReply->readRead(); \\for to read only body
qDebug() << data;
decoder(data); // here i am passing the xml body only
.
.
.
.
.
}
Does my understanding is correct ????
Bookmarks