Hello, i making a simple currency converter and i ran into some trouble with class communication.
I have a class for downloading the exchange rates which saves the values into a text file, and another class to parse the file and save the values in a QMap which i declated in my main.
i wont post the downloader and parser classes since they work as intented
int main(int argc, char *argv[])
{
QMap<QString,double> currency_map;
downloader d;
d.Do_download();
//do the downloading
MainWindow w(currency_map);
w.show();
//make the main window and send the map into it.
parser p;
p.read_line(currency_map);
//parsing the file and saving the values.
p.print_map(currency_map);
//test to see if my values are saved.
Calculator c(currency_map, w);
// cannot convert parameter 1 from 'QMap<Key,T>' to 'QMap<Key,T>'* is the error i get
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMap<QString,double> currency_map;
downloader d;
d.Do_download();
//do the downloading
MainWindow w(currency_map);
w.show();
//make the main window and send the map into it.
parser p;
p.read_line(currency_map);
//parsing the file and saving the values.
p.print_map(currency_map);
//test to see if my values are saved.
Calculator c(currency_map, w);
// cannot convert parameter 1 from 'QMap<Key,T>' to 'QMap<Key,T>'* is the error i get
return a.exec();
}
To copy to clipboard, switch view to plain text mode
my calculator.h
#include <QObject>
#include <QString>
#include <QDebug>
#include <ui_mainwindow.h>
#include "MainWindow.h"
class Calculator
{
public:
explicit Calculator
(QMap <QString, double>
*my_map, Ui
::MainWindow &window
);
private:
Ui::MainWindow *ui;
QMap <QString, double>
*map_pointer;
double x , y;
};
my calculator.h
#include <QObject>
#include <QString>
#include <QDebug>
#include <ui_mainwindow.h>
#include "MainWindow.h"
class Calculator
{
public:
explicit Calculator(QMap <QString, double> *my_map, Ui::MainWindow &window);
void get_value(QString value);
private:
Ui::MainWindow *ui;
QMap <QString, double> *map_pointer;
double x , y;
};
To copy to clipboard, switch view to plain text mode
and calculator.cpp
#include "calculator.h"
Calculator::Calculator(QMap<QString, double> *my_map, Ui::MainWindow *window)
{
map_pointer = my_map;
this->ui= window;
//I get a overloaded member function not found in calculator
}
void Calculator
::get_value(QString value
) {
for(QMap<QString, double>::Iterator i = map_pointer->begin();i != map_pointer->end();i++)
{
if(i.key() == value)
{
qDebug()<<i.key() << ": " << i.value();
}
}
}
#include "calculator.h"
Calculator::Calculator(QMap<QString, double> *my_map, Ui::MainWindow *window)
{
map_pointer = my_map;
this->ui= window;
//I get a overloaded member function not found in calculator
}
void Calculator::get_value(QString value)
{
for(QMap<QString, double>::Iterator i = map_pointer->begin();i != map_pointer->end();i++)
{
if(i.key() == value)
{
qDebug()<<i.key() << ": " << i.value();
}
}
}
To copy to clipboard, switch view to plain text mode
and the MainWindow.h
#include <QMainWindow>
#include <ui_mainwindow.h>
#include "parser.h"
#include "calculator.h"
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QMap<QString, double> currency_map,
QWidget *parent
= 0);
~MainWindow();
private slots:
void on_convert_button_clicked();
void on_from_Combox_currentIndexChanged
(const QString &arg1
);
void on_to_Combox_currentIndexChanged
(const QString &arg1
);
signals:
private:
Ui::MainWindow *ui;
Calculator *calc; //missing type specifier
parser currency_parser;
};
#include <QMainWindow>
#include <ui_mainwindow.h>
#include "parser.h"
#include "calculator.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QMap<QString, double> currency_map, QWidget *parent = 0);
QStringList retrieve_list(parser *p);
~MainWindow();
private slots:
void on_convert_button_clicked();
void on_from_Combox_currentIndexChanged(const QString &arg1);
void on_to_Combox_currentIndexChanged(const QString &arg1);
signals:
private:
Ui::MainWindow *ui;
Calculator *calc; //missing type specifier
parser currency_parser;
};
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
MainWindow
::MainWindow(QMap<QString, double> currency_map,
QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
calc = new Calculator(currency_map,ui);
//missing type specifier
ui->from_Combox->addItems(retrieve_list(¤cy_parser));
ui->to_Combox->addItems(retrieve_list(¤cy_parser));
}
{
return p->currency_list;
}
MainWindow::~MainWindow()
{
delete ui;
delete calc;
}
#include "mainwindow.h"
MainWindow::MainWindow(QMap<QString, double> currency_map, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
calc = new Calculator(currency_map,ui);
//missing type specifier
ui->from_Combox->addItems(retrieve_list(¤cy_parser));
ui->to_Combox->addItems(retrieve_list(¤cy_parser));
}
QStringList MainWindow::retrieve_list(parser *p)
{
return p->currency_list;
}
MainWindow::~MainWindow()
{
delete ui;
delete calc;
}
To copy to clipboard, switch view to plain text mode
The idea was to have a map in main for the exchange rates, fill it with data in the parser class.
and then use the calculator class to calculate the values needed.
I had a "plan" to send the map into the class, along with a pointer on the mainwindow object, so the calculator class could display the result in the display widgets in the mainwindow object, but i cant figure out what im missing here.
If someone could make me and example of how to use signals and slots for the communication i need here, that would be very much appreciated.
Bookmarks