Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED]Help - Unclear errors - Don't know where to post.



  • Hi, first off all I'm sorry if I posted this in the incorrect section, the forums are kinda unclear for me. Also, I'm new to QT since a few days, I know basic C++ and I tried to make a payday calculator, I'm stuck with some code. The errors seem unclear for me, thanks in advance and again I'm sorry if I posted this incorrectly. Also, the script itself isn't made to work yet like it should, I just needed to do some testing first.

    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent):QMainWindow(parent),ui(new Ui::MainWindow){

    ui->setupUi(this);
    ui->mainTable->setColumnWidth(0,50);
    ui->mainTable->setColumnWidth(1,151);
    
    ui->mainTable->verticalHeader()->setVisible(false);
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::addTaxes(int time, int taxes, int net){
    int x = 0;
    int rate = 2;

    ui->mainTable->setRowCount(time);
    
    for(int i=0; i<time; i++){
        QTableWidgetItem* item = new QTableWidgetItem();
        QTableWidgetItem* itemDeux = new QTableWidgetItem();
    
        x = ((net/100)*rate)-taxes;
        net = net + x;
        item->setText(QString::number(i));
        ui->mainTable->setItem(i,0,item);
    
        itemDeux->setText("$" + QString::number(net));
        ui->mainTable->setItem(i,1,itemDeux);
    
        ui->mainTable->setRowHeight(i,10);
    }
    

    }

    void MainWindow::on_calculateButton_clicked(){
    //int time = ui->timeEdit->text().toInt();
    int taxes = 0;
    int net = 0;
    int time = 0;

    addTaxes(time,taxes,net);
    

    }
    @

    errors:
    @C:\Users\Robbe\Desktop\workspace\PaydayCalculator\mainwindow.cpp:19: error: prototype for 'void MainWindow::addTaxes(int, int, int)' does not match any in class 'MainWindow'
    void MainWindow::addTaxes(int time, int taxes, int net){
    ^@

    @C:\Users\Robbe\Desktop\workspace\PaydayCalculator\mainwindow.h:23: error: candidate is: void MainWindow::addTaxes()
    void addTaxes();
    ^@
    @C:\Users\Robbe\Desktop\workspace\PaydayCalculator\mainwindow.cpp:47: error: no matching function for call to 'MainWindow::addTaxes(int&, int&, int&)'
    addTaxes(time,taxes,net);
    ^@

    header
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private slots:
    void on_calculateButton_clicked();

    private:
    Ui::MainWindow *ui;
    void addTaxes();
    };

    #endif // MAINWINDOW_H
    @


  • Moderators

    Hi, and welcome to the Qt Dev Net!

    What you say in your .h file needs to match what you say in your .cpp file:

    [quote]
    @
    // mainwindow.h
    void addTaxes();
    @

    @
    // mainwindow.cpp
    void MainWindow::addTaxes(int time, int taxes, int net){
    ...
    @
    [/quote]Your .h file says addTaxes takes 0 parameters, but your .cpp file says it takes 3 int parameters. Which is is correct?



  • [quote author="JKSH" date="1396831350"]Hi, and welcome to the Qt Dev Net!

    What you say in your .h file needs to match what you say in your .cpp file:

    [quote]
    @
    // mainwindow.h
    void addTaxes();
    @

    @
    // mainwindow.cpp
    void MainWindow::addTaxes(int time, int taxes, int net){
    ...
    @
    [/quote]Your .h file says addTaxes takes 0 parameters, but your .cpp file says it takes 3 int parameters. Which is is correct?[/quote]

    Thanks a lot, I knew about this but I forgot to add the parameters to the header file as you said.


Log in to reply