0

I am creating a QTableView formed of 6 columns that inserts specific values by calling a dialog. When I compile the project I receive the following errors in the file 'itemcameracalibrationdata.h':

note: candidate expects 6 arguments, 0 provided

note: candidate expects 6 arguments, 1 provided

For completeness I am including below both the 6 variables and the dialog file: Below the itemcalibrationdata.h

#ifndef ITEMCAMERACALIBRATIONDATA_H
#define ITEMCAMERACALIBRATIONDATA_H

#include <QObject>
#include <QString>

class itemCameraCalibrationData
{
public:
    itemCameraCalibrationData(const QString &cameraName, const double fovx, const double fovy,
                              int version, const double focalLenghth,
                              const double reprojectionerror);

    QString cameraName() const { return mCameraName;}
    int version() const { return mVersion; }
    double fovx() const { return mFovx; }
    double fovy() const { return mFovy; }
    double focalLenghth() const { return mFocalLenghth; }
    double reprojectionerror() const { return mReprojectionError; }

private:
    QString mCameraName;
    int mVersion;
    double mFovx;
    double mFovy;
    double mFocalLenghth;
    double mReprojectionError;

};

#endif // ITEMCAMERACALIBRATIONDATA_H

Below the itemcalibrationdata.cpp

#include "itemcameracalibrationdata.h"

itemCameraCalibrationData::itemCameraCalibrationData(const QString &cameraName, const double fovx, const double fovy,
                                                     int version, const double focalLenghth,
                                                     const double reprojectionerror)
{
    mCameraName = cameraName;
    mFovx = fovx;
    mFovy = fovy;
    mVersion = version;
    mFocalLenghth = focalLenghth;
    mReprojectionError = reprojectionerror;
}

Then see the cameracaldialog.cpp and the error is in this file at the line ui(new Ui::cameraCalDialog)

#include "cameracaldialog.h"
#include "ui_cameracaldialog.h"
#include "itemcameracalibrationdata.h"

#include <QFile>
#include <QMessageBox>
#include <QFileDialog>
#include <QCompleter>
#include <QFileSystemModel>

cameraCalDialog::cameraCalDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::cameraCalDialog)
{

    ui->setupUi(this);
}

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

void cameraCalDialog::on_buttonBox_accepted()
{
    mItemCamCal = itemCameraCalibrationData(ui->camName_lineEdit->text(),
                                            ui->ver_lineEdit->text().toInt(),
                                            ui->fovx_lineEdit->text().toDouble(),
                                            ui->fovy_lineEdit->text().toDouble(),
                                            ui->focal_lineEdit->text().toDouble(),
                                            ui->rep_lineEdit->text().toDouble());
    accept();
}

void cameraCalDialog::on_buttonBox_rejected()
{
    rejected();
}

as last file the cameracaldialog.h

#ifndef CAMERACALDIALOG_H
#define CAMERACALDIALOG_H

#include <QDialog>
#include "itemcameracalibrationdata.h"


namespace Ui {
class cameraCalDialog;
}

class cameraCalDialog : public QDialog
{
    Q_OBJECT

public:
    explicit cameraCalDialog(QWidget *parent = nullptr);
    ~cameraCalDialog();
    itemCameraCalibrationData itemCamCal() const { return mItemCamCal; }


private slots:
    void on_buttonBox_accepted();
    void on_buttonBox_rejected();

private:
    Ui::cameraCalDialog *ui;
    itemCameraCalibrationData mItemCamCal;
};

#endif // CAMERACALDIALOG_H

Thank you very much for any insight you can provide on this matter

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 2
    Advice -- You could have attempted a [mcve], such as [this one](https://www.ideone.com/BFZwwq). See the issue now? – PaulMcKenzie Apr 30 '18 at 01:00

2 Answers2

1

When you use:

itemCameraCalibrationData mItemCamCal; 

in the .h you are creating a new object, but the class itemCameraCalibrationData needs parameters, for that reason it throws the error.

In your case you do not want to create it in the .h but in the slot on_buttonBox_accepted so the solution is to declare a pointer in the .h and use new to create the object:

*.h

class cameraCalDialog : public QDialog
{
    ...

private:
    Ui::cameraCalDialog *ui;
    itemCameraCalibrationData *mItemCamCal;
};

*.cpp

cameraCalDialog::~cameraCalDialog()
{
    delete ui;
    delete mItemCamCal;
}


void cameraCalDialog::on_buttonBox_accepted()
{
    mItemCamCal = new itemCameraCalibrationData(ui->camName_lineEdit->text(),
                                            ui->ver_lineEdit->text().toInt(),
                                            ui->fovx_lineEdit->text().toDouble(),
                                            ui->fovy_lineEdit->text().toDouble(),
                                            ui->focal_lineEdit->text().toDouble(),
                                            ui->rep_lineEdit->text().toDouble());
    accept();
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thank you very much eyllanesc. It is compiling and didn't realize about that! Thanks PaulMcKenzie for the documentation/source provided, they are very helpful. –  Apr 30 '18 at 01:31
  • @Emanuele Also, if you really wanted to instantiate the `itemCameraCalibrationData` with 6 parameters on construction of the `cameraDialog`, you would use the [member initialization list](https://stackoverflow.com/questions/926752/why-should-i-prefer-to-use-member-initialization-list), i.e. `cameraDialog(QWidget *parent) : itemCameraCalibrationData(arg1, arg2, etc.) {}` – PaulMcKenzie Apr 30 '18 at 02:17
  • This answer suggests manual dynamic memory allocation, and associated indirection costs, as a fix for the missing default constructor... – Kuba hasn't forgotten Monica Apr 30 '18 at 19:17
1
  1. You need a default constructor.
  2. Polluting the interface with const value parameters is pointless. The const belongs in the implementation, and yes, the signatures can differ that way. The language is designed that way on purpose.
  3. Use initializer lists.
// itemcameracalibrationdata.cpp
#pragma once
#include <QString>

class itemCameraCalibrationData {
public:
    itemCameraCalibrationData() = default;
    itemCameraCalibrationData(const QString &cameraName, 
                              double fovx, double fovy,
                              int version, double focalLenghth,
                              double reprojectionerror);

    QString cameraName() const { return mCameraName;}
    int version() const { return mVersion; }
    double fovx() const { return mFovx; }
    double fovy() const { return mFovy; }
    double focalLenghth() const { return mFocalLenghth; }
    double reprojectionerror() const { return mReprojectionError; }
private:
    QString mCameraName;
    int mVersion = {};
    double mFovx = {};
    double mFovy = {};
    double mFocalLenghth = {};
    double mReprojectionError = {};
};
// itemcameracalibrationdata.cpp
#include "itemcameracalibrationdata.h"

itemCameraCalibrationData::itemCameraCalibrationData(
    const QString &cameraName, const double fovx, const double fovy,
    const int version, const double focalLenghth, const double reprojectionerror)
:
    mCameraName(cameraName),
    mFovx(fovx),
    mFovy(fovy),
    mVersion(version),
    mFocalLenghth(focalLenghth),
    mReprojectionError(reprojectionerror)
{}
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313