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