16,213
社区成员
发帖
与我相关
我的任务
分享
//类的.cpp文件
#include "test.h"
#include "ui_mainwindow.h"
Test::Test(){
}
void Test::SetText(MainWindow &mw){
mw.ui->lineEdit->setText("CodeLab");
}
//类的.h文件
#ifndef TEST_H
#define TEST_H
#include <mainwindow.h>
#include "ui_mainwindow.h"
class Test{
public:
Test();
void SetText(MainWindow &mw);
};
#endif // TEST_H
//mian.cpp进行调用
#include "mainwindow.h"
#include <QApplication>
#include <test.h>
int main(int argc, char *argv[]){
QApplication a(argc, argv);
MainWindow w;
w.show();
Test test;
test.SetText(w);
return a.exec();
}
不知道这样是否能实现你想要的功能