What is the actuall syntax to pass a variable to C++ class / constructor ?
-
I plead ignorance...so sue me...
I want to pass a variable , either int or better a whole QString ...
My objective is to simply show a variable (int) related or direct text message when the class in used.
I have never grasped the correct way to pass variables to C++ constructor - my fault...
I would prefer a code (example) instead of "RTFM" suggestions...namespace Ui {
class Form_MDI;
}class Form_MDI : public QWidget
{
Q_OBJECTpublic:
explicit Form_MDI(QWidget *parent = nullptr);
~Form_MDI();private:
Ui::Form_MDI *ui;
};#endif // FORM_MDI_H
Form_MDI::Form_MDI(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form_MDI)
{
ui->setupUi(this);
}Form_MDI::~Form_MDI()
{
delete ui;
} -
I plead ignorance...so sue me...
I want to pass a variable , either int or better a whole QString ...
My objective is to simply show a variable (int) related or direct text message when the class in used.
I have never grasped the correct way to pass variables to C++ constructor - my fault...
I would prefer a code (example) instead of "RTFM" suggestions...namespace Ui {
class Form_MDI;
}class Form_MDI : public QWidget
{
Q_OBJECTpublic:
explicit Form_MDI(QWidget *parent = nullptr);
~Form_MDI();private:
Ui::Form_MDI *ui;
};#endif // FORM_MDI_H
Form_MDI::Form_MDI(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form_MDI)
{
ui->setupUi(this);
}Form_MDI::~Form_MDI()
{
delete ui;
}@AnneRanch
It's no different from any other method/function. I've added oneint
and oneQString
:explicit Form_MDI(int someInt, QString someString, QWidget *parent = nullptr); ... Form_MDI::Form_MDI(int someInt, QString someString, QWidget *parent) : ... // Caller example: Form_MDI *formMDI = new Form_MDI(42, "Hello World", this);
-
I spend a lot of time here to understand the internals of C++.