Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Qt中传入参数UI_C++_Qt - Fatal编程技术网

C++ 在Qt中传入参数UI

C++ 在Qt中传入参数UI,c++,qt,C++,Qt,我在Qt项目中有一个windows ui,我想将此ui in参数传递给另一个函数,如下所示: ConfWindows::ConfWindows(QWidget *parent) : QDialog(parent), ui(new Ui::ConfWindows) { ui->setupUi(this); connect(ui->add_button, SIGNAL(clicked()), this, SLOT(add_elem(ui->name_edit)))

我在Qt项目中有一个windows ui,我想将此ui in参数传递给另一个函数,如下所示:

ConfWindows::ConfWindows(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfWindows)
{
    ui->setupUi(this);

    connect(ui->add_button, SIGNAL(clicked()), this, SLOT(add_elem(ui->name_edit)));
}

void        add_elem(QLabel test)
{
    qDebug() << test.text();
}
不可能在参数中传递ui元素


谢谢您的帮助。

首先,将ui作为参数传递不是一个好的做法。 其次,插槽的功能原型中的参数不能超过信号的参数

我应该这样做: 我将创建add_elem函数,它是
ConfWindows
类的成员函数,以便访问其主体内的ui并获取标签的文本

ConfWindows::ConfWindows(QWidget *parent) :
QDialog(parent), ui(new Ui::ConfWindows) {
    ui->setupUi(this);

    connect(ui->add_button, SIGNAL(clicked()), this, SLOT(add_elem()));
}

void ConfWindows::add_elem() {
    QString text = ui->label->text();
    qDebug() << test.text();
}
ConfWindows::ConfWindows(QWidget*父项):
QDialog(父级)、ui(新ui::ConfWindows){
用户界面->设置用户界面(此);
连接(ui->add_按钮,信号(点击()),此,插槽(add_元素());
}
void ConfWindows::add_elem(){
QString text=ui->label->text();

qDebug()通过
常量和
?像这样?
无效添加元素(QLabel常量和测试){qDebug()不应该是
插槽(添加元素(QLabel)))
首先?另外,是否复制被禁用,请按常量引用传递。@Sonny如果在标题中更改它,您还必须在cpp文件中更改它。您不能将QLineEdit传递到需要QLabel的插槽中。您应该研究如何从行编辑中获取文本并设置标签的文本。
ConfWindows::ConfWindows(QWidget *parent) :
QDialog(parent), ui(new Ui::ConfWindows) {
    ui->setupUi(this);

    connect(ui->add_button, SIGNAL(clicked()), this, SLOT(add_elem()));
}

void ConfWindows::add_elem() {
    QString text = ui->label->text();
    qDebug() << test.text();
}