Hey, so i'm making this currency converter app for a school project.
I have a class which downloads a html using QT, and saves it into a .txt file. it was all working good, but then i had to change my .txt hardcoded path into a relative one, and i ran into some wierd issue while trying to put that aditional functionality into the class.
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
|
#ifndef DOWNLOADER_H
#define DOWNLOADER_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QFile>
#include <QDebug>
#include <QMessageBox>
#include <string>
#include <Windows.h>
#include <qstring.h>
class downloader : public QObject
{
Q_OBJECT
public:
explicit downloader(QObject *parent = 0);
void Do_download();
std::string getExePath();
public slots:
void replyFinished (QNetworkReply *reply);
private:
QNetworkAccessManager *manager;
};
#endif // DOWNLOADER_H
|
.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
|
#include "downloader.h"
#include "strings.h"
#include <string>
#include <Windows.h>
downloader::downloader(QObject *parent) :
QObject(parent)
{
}
std::string::getExePath()
{
char result[MAX_PATH];
return std::string(result,GetModuleFileNameA(NULL, result, MAX_PATH));
}
void downloader::Do_download()
{
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)
{
if(reply->error())
{
QMessageBox msgBox;
msgBox.setText(strings::msgBoxDownReplyError);
msgBox.exec();
}
else
{
// skidanje podataka i spremanje u text dokument
QFile *file = new QFile(QString::fromStdString(getExePath()));
QByteArray data = reply->readAll();
if(file->open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text))
{
file->write(data);
file->flush();
file->close();
}
delete file;
}
reply->deleteLater();
}
|
1>downloader.cpp(13): error C2039: 'getExePath' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1>downloader.cpp(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>downloader.cpp(16): error C2440: 'return' : cannot convert from 'std::basic_string<_Elem,_Traits,_Ax>' to 'int'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>downloader.cpp(17): error C2617: 'getExePath' : inconsistent return statement
1> downloader.cpp(13) : see declaration of 'getExePath'
these are the errors i get