#ifndef MAINWINDOW_H#define MAINWINDOW_H #include <QMainWindow>#include "test.h" QT_BEGIN_NAMESPACEnamespace Ui { class MainWindow; }QT_END_NAMESPACE class MainWindow : public QMainWindow{ Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); void set_tw_check_file_insert_row(); private slots: void on_pushButton_clicked(); private: Ui::MainWindow *ui;};#endif // MAINWINDOW_H
#include "mainwindow.h"#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow){ ui->setupUi(this);} MainWindow::~MainWindow(){ delete ui;} void MainWindow::set_tw_check_file_insert_row(){ ui->tableWidget->insertRow(ui->tableWidget->rowCount());}
#ifndef TEST_H#define TEST_H class Test{public: Test(); void calculate();}; #endif // TEST_H
#include "test.h"#include "mainwindow.h" Test::Test(){ } void Test::calculate(){ MainWindow mw; mw.set_tw_check_file_insert_row();}
set_tw_check_file_insert_row();
C++ (Qt)class Test : public QObject{Q_OBJECTpublic:Test();void calculate(){/* work hard*/emit calcDone();}signals:void calcDone();};
C++ (Qt)connect(TestObject, &Test:calcDone, this, &MainWindow::set_tw_check_file_insert_row);
C++ (Qt)void MainWindow::on_pushButton_clicked(){ Test t; t.calculate(); set_tw_check_file_insert_row();}
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include "test.h"QT_BEGIN_NAMESPACEnamespace Ui { class MainWindow; }QT_END_NAMESPACEclass MainWindow : public QMainWindow{ Q_OBJECTpublic: Test *t;