lll
lll

Reputation: 332

Qt, pass data to another class

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);

Upvotes: 1

Views: 956

Answers (1)

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);

Upvotes: 3

Related Questions