thx, that helped. now if i can trouble you some more 
so i have this parser class im making
#include <QFile>
#include <QTextStream>
#include <QString>
#include <QTextStream>
#include <QMessageBox>
#include <QDebug>
#include <QStringList>
{
Q_OBJECT
public:
explicit parser
(QObject *parent
= 0);
int read_line();
void init_map();
void init_list();
private:
QMap<QString,float> map;
};
#include <QFile>
#include <QTextStream>
#include <QString>
#include <QTextStream>
#include <QMessageBox>
#include <QDebug>
#include <QStringList>
class parser : public QObject
{
Q_OBJECT
public:
explicit parser(QObject *parent = 0);
void process_line(QString line);
int read_line();
void init_map();
void init_list();
private:
QMap<QString,float> map;
QStringList valute;
};
To copy to clipboard, switch view to plain text mode
and the .cpp
#include "parser.h"
{
init_map();
init_list();
}
void parser
::process_line(QString line
) {
if(line.contains(str,Qt::CaseInsensitive)) this is the part im having trouble with now**
{
qDebug()<<"found euro";
temporary_list
=line.
split(" ",
QString::SkipEmptyParts);
map.insert("EUR",temporary_list[6].toFloat());
}
}
int parser::read_line()
{
QFile file("C:/downloaded.txt");
if(!file.exists())
{
msgBox.setText("There is no such file");
msgBox.exec();
return 1;
}
{
msgBox.setText("Error while opening file");
return 1;
}
while (!line.isNull())
{
process_line(line);
line = in_stream.readLine();
}
return 0;
}
void parser::init_map()
{
map.insert("AUD",0);
map.insert("CAD",0);
map.insert("CZK",0);
map.insert("DKK",0);
map.insert("NOK",0);
map.insert("SEK",0);
map.insert("CHF",0);
map.insert("GBP",0);
map.insert("USD",0);
map.insert("EUR",0);
map.insert("PLN",0);
}
void parser::init_list()
{
valute << "AUD" << "CAD" << "CZK" << "DKK" << "NOK" << "SEK"
<< "CHF" << "GBP" << "USD" << "EUR" << "PLN";
}
#include "parser.h"
parser::parser(QObject *parent) :
QObject(parent)
{
init_map();
init_list();
}
void parser::process_line(QString line)
{
QString str="EUR";
QStringList temporary_list;
if(line.contains(str,Qt::CaseInsensitive)) this is the part im having trouble with now**
{
qDebug()<<"found euro";
temporary_list=line.split(" ", QString::SkipEmptyParts);
map.insert("EUR",temporary_list[6].toFloat());
}
}
int parser::read_line()
{
QFile file("C:/downloaded.txt");
if(!file.exists())
{
QMessageBox msgBox;
msgBox.setText("There is no such file");
msgBox.exec();
return 1;
}
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox msgBox;
msgBox.setText("Error while opening file");
return 1;
}
QTextStream in_stream(&file);
QString line=in_stream.readLine();
while (!line.isNull())
{
process_line(line);
line = in_stream.readLine();
}
return 0;
}
void parser::init_map()
{
map.insert("AUD",0);
map.insert("CAD",0);
map.insert("CZK",0);
map.insert("DKK",0);
map.insert("NOK",0);
map.insert("SEK",0);
map.insert("CHF",0);
map.insert("GBP",0);
map.insert("USD",0);
map.insert("EUR",0);
map.insert("PLN",0);
}
void parser::init_list()
{
valute << "AUD" << "CAD" << "CZK" << "DKK" << "NOK" << "SEK"
<< "CHF" << "GBP" << "USD" << "EUR" << "PLN";
}
To copy to clipboard, switch view to plain text mode
i have a txt file of over 60 lines from which i have to read the values.
so i would like my process_line function to check the QString it receives if there is any matching strings from my QStringlist in there.
and if so to insert the value to my map.
im not sure how to write that in my if statement, and im pretty sure also i have the wrong aproach here. so if you could point me in the right direction again, would be very much appreciated.
Bookmarks