Problem with references

Hey, so i got a std::map in my main which i use in other classes for reading or writing into it.
It was all working well but i had a bug in my code, becuase of which i had to make some adjustments to the code and now the map is not wokring as i would like it to work. In other words, the writing into it works, but the map is empty once i exit downloader scope.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    std::map<std::string,double> currency_map;

    downloader d(currency_map);
    d.Do_download();
	
    MainWindow w(currency_map);
    w.show();
	
    return a.exec();
};


downloader.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class downloader : public QObject
{
    Q_OBJECT
public:
    explicit downloader(std::map<std::string,double> &my_map,QObject *parent = 0);

    void Do_download();

	std::string getExePath();

	void Do_parse(QNetworkReply *reply);

public slots:
    void replyFinished (QNetworkReply *reply);

private:
    QNetworkAccessManager *manager;
	bool downloadSuccess;
	std::map<std::string,double> &map;

};


and .cpp

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
55
56
57
58
59
60
61
62
63
64
downloader::downloader(std::map<std::string,double> &my_map,QObject *parent) :
    QObject(parent), map(my_map)
{
	downloadSuccess = false;
	
}


std::string downloader::getExePath()
{
	char result[MAX_PATH];
	return std::string(result,GetModuleFileNameA(NULL, result, MAX_PATH));
}

void downloader::Do_download()
{
	qDebug() << "1" ;
    manager = new QNetworkAccessManager(this);

    connect(manager, SIGNAL(finished(QNetworkReply*)),
            this,SLOT(replyFinished(QNetworkReply*)));

            manager->get(QNetworkRequest(QUrl("http://www.hnb.hr/tecajn/hvazeca.htm")));
			
}

void downloader::replyFinished(QNetworkReply *reply)
{
	qDebug()<< "2" ;
    if(reply->error())
    {
        QMessageBox msgBox;
		msgBox.setText(strings::msgBoxDownReplyError);
        msgBox.exec();
		downloadSuccess = false;
    }
    else
    {
		downloadSuccess = true;
	}
	if(downloadSuccess)
	Do_parse(reply);
	reply->manager()->deleteLater();
}

void downloader::Do_parse(QNetworkReply *reply)
{
	 qDebug() << "3" ;
		QFile *file = new QFile(strings::filePathQt);
        QByteArray data = reply->readAll();

        if(file->open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text))
            {
            file->write(data);
            file->flush();
            file->close();
        }
        delete file;

    reply->deleteLater();
	parser p;
	p.read_line(map);

}

The parsing works, when i debugg the code, my map has the data i need in it, but after that it just dissaperas.
I cant grasp on why is that.
I make a reference on the map in my downloader class, i initilaze it before the constructor(because i have to, since i cant change the object to which the ref is pointing at) and i use the map reference in my code.
From reading about ref's and pointers, im quite sure im working with the EXCACT same map all the time, but still...

Can someone help me out and find out why the data isn't saved?
map(my_map) calls the copy constructor , look if this is the issue .
> map(my_map) calls the copy constructor
no, it doesn't.

> the writing into it works
¿where do you ever fill the map?

> i exit downloader scope.
¿what's downloader scope?
Topic archived. No new replies allowed.