- import.h
#pragma once #include "ui_QtWidgetsApplication.h" //头文件 class import { public: Ui::QtWidgetsApplicationClass* cui = NULL; //ui指针 import(); void getDeviceNum(); //函数 };
- import.cpp
#include "import.h" #include <qdebug.h> import::import() { } void import::getDeviceNum() // { QString str = cui->pushButton_getDeviceNum->text(); qDebug() << str; }
- QtWidgetsApplication.h
#pragma once #include <QtWidgets/QWidget> #include "ui_QtWidgetsApplication.h" #include "import.h" //头文件 #if _MSC_VER >= 1600 #pragma execution_character_set("utf-8") #endif class QtWidgetsApplication : public QWidget { Q_OBJECT public: QtWidgetsApplication(QWidget *parent = nullptr); ~QtWidgetsApplication(); public: void initDevice(); private: Ui::QtWidgetsApplicationClass *ui; //!!!使用指针 import cest; };
- QtWidgetsApplication.cpp
#include "QtWidgetsApplication.h" #include "import.h" QtWidgetsApplication::QtWidgetsApplication(QWidget *parent) : QWidget(parent) { ui->setupUi(this); //指针 cest.cui = ui; //!!!指针赋值 connect(ui->pushButton_init, &QPushButton::clicked, this, &QtWidgetsApplication::initDevice); } QtWidgetsApplication::~QtWidgetsApplication() { } void QtWidgetsApplication::initDevice() { cest.getDeviceNum(); }
- ui文件
/* ... */