Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.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++ Qt5从另一个类访问ui_C++_Qt_Qt5_Qt Creator - Fatal编程技术网

C++ Qt5从另一个类访问ui

C++ Qt5从另一个类访问ui,c++,qt,qt5,qt-creator,C++,Qt,Qt5,Qt Creator,我创建了一个类datafunctions,我想在其中存储在mainwindow中更新UI小部件的每个函数。因此,我尝试将ui作为参数传递给函数。假设我想更改作为主窗口一部分的textEdit_数据小部件的文本。在将ui作为参数传递到dataFunctions类中的函数formatandInsert之后,我无法访问MainWindowUI的任何小部件。下面的代码给出了错误“成员访问不完整的类型'Ui::MainWindow'” 这是我的datafunctions.h文件 #ifndef DATAF

我创建了一个类datafunctions,我想在其中存储在mainwindow中更新UI小部件的每个函数。因此,我尝试将ui作为参数传递给函数。假设我想更改作为主窗口一部分的textEdit_数据小部件的文本。在将ui作为参数传递到dataFunctions类中的函数formatandInsert之后,我无法访问MainWindowUI的任何小部件。下面的代码给出了错误“成员访问不完整的类型'Ui::MainWindow'”

这是我的datafunctions.h文件

#ifndef DATAFUNCTIONS_H
#define DATAFUNCTIONS_H

#include "mainwindow.h"
#include <QTextEdit>

class dataFunctions
{
public:
    dataFunctions();
    void formatandInsert(Ui::MainWindow*);
};

#endif // DATAFUNCTIONS_H

您需要在
datafunctions.cpp
文件中包含“ui\u mainwindow.h”。这是一个由Qt Designer自动生成的标题,它定义了
Ui::MainWindow
类。

不清楚您所说的“我仍然无法访问Ui”是什么意思。看来你得到了比你预期的更多的东西。你所期望的和你所得到的并没有被描述。同样,formatandInsert所做的转换也不见了。@ÖÖTiib我更新了它
#ifndef DATAFUNCTIONS_H
#define DATAFUNCTIONS_H

#include "mainwindow.h"
#include <QTextEdit>

class dataFunctions
{
public:
    dataFunctions();
    void formatandInsert(Ui::MainWindow*);
};

#endif // DATAFUNCTIONS_H
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    dataFunctions df;
    df.formatandInsert(ui);
}