Answer the question
In order to leave comments, you need to log in
How to pass parameters to parent object slot?
I reviewed many different examples, but did not understand how to pass parameters to the slot of the parent object.
The class of the object passing the parameters:
class MakeTable : public QDialog
{
public:
MakeTable(QWidget* parent = nullptr);
private:
QGridLayout* lay;
qint16 width;
qint16 height;
QLabel* w;
QLabel* h;
QSpinBox* setWidth;
QSpinBox* setHeight;
QPushButton* ok;
QPushButton* cancel;
public slots:
void reject();
};
MakeTable::MakeTable(QWidget* parent)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
{
w = new QLabel("Введите количество столбцов таблицы");
h = new QLabel("Введите количество строк таблицы");
setWidth = new QSpinBox;
setHeight = new QSpinBox;
setWidth->setMaximumWidth(50);
setWidth->setMaximum(1024);
setWidth->setMinimum(1);
setWidth->setValue(32);
setHeight->setMaximumWidth(50);
setHeight->setMaximum(1024);
setWidth->setMinimum(1);
setHeight->setValue(32);
w->setBuddy(setWidth);
h->setBuddy(setHeight);
ok = new QPushButton("ОК");
cancel = new QPushButton("Отмена");
width = qint16(setWidth->value());
height = qint16(setHeight->value());
connect(ok, SIGNAL(clicked()), parent, SLOT(makeTable(width, height))); //Здесь непонятный момент.
connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
lay = new QGridLayout;
lay->addWidget(w,0,0);
lay->addWidget(h,1,0);
lay->addWidget(setWidth,0,1);
lay->addWidget(setHeight,1,1);
lay->addWidget(ok, 2,0);
lay->addWidget(cancel, 2,1);
setLayout(lay);
this->setFixedSize(320,100);
this->show();
this->exec();
}
void Widget::makeTable(qint16 width, qint16 height);
Answer the question
In order to leave comments, you need to log in
In the connect function, the slot must contain a function description with the type of parameters, for example,
True, this will not solve the problem with passing parameters to the slot, because the signal does not contain parameters. To do this, use local class member variables.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question