1

I want to pass int testing to dialog.cpp when a push button is clicked from the mainwindow.cpp.

I got an error message as follows: "missing default argument on parameter testing"

What did I do wrong?

dialog.h

#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = nullptr, const int & testing);
    ~Dialog();

private:
    Ui::Dialog *ui;
};

dialog.cpp

Dialog::Dialog(QWidget *parent, const int & testing) :
    QDialog(parent),
    ui(new Ui::Dialog)
{   
}

mainwindow.cpp

dialog = new Dialog(this, *testing);
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
lll
  • 302
  • 3
  • 13
  • 2
    `explicit Dialog(QWidget *parent = nullptr, const int & testing);` you need to supply the default value from right to left. https://www.quora.com/Why-are-default-arguments-assigned-from-right-to-left-in-C++ – drescherjm Apr 16 '19 at 01:47
  • 2
    What is the purpose for the testing parameter? Why is it pass by reference for a single integer? Is there some logical default value for this parameter? – drescherjm Apr 16 '19 at 01:49
  • I want to pass data to Dialog.ui from mainwindow.cpp. – lll Apr 16 '19 at 01:55

1 Answers1

3

this is invalid:

Dialog(QWidget *parent = nullptr, const int & testing);

because default values must be always after non ones.... so your integer parameter "testing" can not be placed after parent.

do set a default value for he integer:

Dialog(QWidget *parent = nullptr, const int & testing = 0);

or change its order in the constructor

Dialog(const int & testing, QWidget *parent = nullptr);
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97