我正在创建一个由6列组成的QTableView,它通过调用对话框来插入特定值。当我编译项目时,我在文件' itemcameracalibrationdata.h'中收到以下错误:
注意:候选人需要6个参数,0提供
注意:候选人需要6个参数,1个提供
为了完整性,我在6个变量和对话框文件中包括: 在 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
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;
}
然后看 cameracaldialog.cpp ,错误在此文件的 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();
}
作为最后一个文件 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
非常感谢您就此事提供的任何见解
答案 0 :(得分:1)
使用时:
itemCameraCalibrationData mItemCamCal;
itemCameraCalibrationData
需要参数,因此它会抛出错误。
在您的情况下,您不希望在.h中创建它,但在插槽on_buttonBox_accepted
中创建它,因此解决方案是在.h中声明指针并使用new
创建对象:
<强> *的.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();
}
答案 1 :(得分:0)
const
值参数对接口进行污染是没有意义的。 const
属于实现,是的,签名可以有不同的方式。该语言是按照目的设计的。// 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)
{}