Extraire des string/char d'un fichier texte
Bonjour à tous !
Je suis actuellement en train de créer un programme en QT qui récupère le code source d'une page web et le copie dans un fichier texte.
Je dois ensuite exploiter le code et récupère certaines chaîne de caractère pour ensuite les stocker dans une base de donnée.
Mon problème est que j'ai chercher longtemps pour récupérer juste quelques String dans mon fichier texte, j'aimerais savoir comment on peut faire, voici mon code qui insere le code source dans le fichier et le lit :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include "Downloader.h"
Downloader::Downloader(QObject *parent) :
QObject(parent)
{
}
void Downloader::doDownload()
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
//code source à récuperer
manager->get(QNetworkRequest(QUrl("http://api.worldweatheronline.com/free/v2/weather.ashx?q=Limoges&format=tab&num_of_days=6&key=9914005e91ae8f64adf3f01723557")));
}
void Downloader::replyFinished (QNetworkReply *reply)
{
if(reply->error())
{
qDebug() << "ERROR!";
qDebug() << reply->errorString();
}
else
{
qDebug() << reply->header(QNetworkRequest::ContentTypeHeader).toString();
qDebug() << reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toString();
qDebug() << reply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
//ecriture dans le fichier
QFile *file = new QFile("C:/Users/roussangea/Documents/Qt Projects/QHttpDownload2/downloaded.txt");
if(file->open(QFile::WriteOnly))
{
file->write(reply->readAll());
file->flush();
file->close();
}
delete file;
}
//fichier à lire
QFile fichier("C:/Users/roussangea/Documents/Qt Projects/QHttpDownload2/downloaded.txt");
QTextStream flux(&fichier);
//ouverture du fichier
fichier.open(QIODevice::ReadOnly | QIODevice::Text);
//lecture de tout le fichier
QString tout = flux.readAll();
qDebug() << tout ;
reply->deleteLater();
} |