#ifndef PROCESSOR_H#define PROCESSOR_H#include <QWidget>class Processor : public QWidget{ Q_OBJECTpublic: Processor(QWidget *parent = 0);private slots: void alert();};#endif // PROCESSOR_H
#include "processor.h"#include <QtDebug>#include <QtGui>Processor::Processor(QWidget *parent): QWidget(parent){}void Processor::alert(){ qDebug() << "alert!!";}
#include <QApplication>#include "mainwindow.h"#include "processor.h"int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); Processor proc1; return a.exec();}
#include <QMainWindow>namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); public: Ui::MainWindow *ui;};
#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this);}MainWindow::~MainWindow(){ delete ui;}
C++ (Qt)MainWindow *w = new MainWindow();SomeFunction(w);...void SomeFunction(MainWindow* window){ ... window->ui ...}