#include "app.h"int main(int argc, char **argv){ CApp app(argc, argv); return app.run();}
#ifndef __GRADARAPP_H__#define __GRADARAPP_H__#include <QApplication>#include "guimanager.h"class CApp : public QApplication{public: CApp(int argc, char** argv); ~CApp(); int run();private: CGuiManager* m_pGuiManager;};#endif // __GRADARAPP_H__
#include "app.h"CApp::CApp(int argc, char** argv): QApplication(argc, argv){ m_pGuiManager = new CGuiManager(this);}CApp::~CApp(){}int CApp::run(){ return exec();}
#include <QObject>#include "mainwin.h"class CGuiManager : public QObject{public: CGuiManager(QObject* parent); ~CGuiManager();private: CMainWindow* m_pMainWindow;};
#include "guimanager.h"CGuiManager::CGuiManager(QObject* parent): QObject(parent){ m_pMainWindow = new CMainWindow;}CGuiManager::~CGuiManager(){ delete m_pMainWindow;}
#ifndef __MAINWIN_H__#define __MAINWIN_H__#include <QMenu>#include <QAction>#include <QToolBar>#include <QMainWindow>class CMainWindow : public QMainWindow{public: CMainWindow(); ~CMainWindow();private: void createActions(); void createMenus(); void createToolBars(); void createStatusBar(); private: QAction* m_pExitAct; QMenu* m_pFileMenu; QToolBar* m_pFileToolBar;};#endif // __MAINWIN_H__
#include <QTextEdit>#include <QMenuBar>#include "mainwin.h"CMainWindow::CMainWindow(){ createActions(); createMenus(); createToolBars(); QTextEdit* edit = new QTextEdit(this); setCentralWidget(edit); show();}CMainWindow::~CMainWindow(){}void CMainWindow::createActions(){ m_pExitAct = new QAction(tr("E&xit"), this); connect(m_pExitAct, SIGNAL(triggered()), this, SLOT(close())); return;}void CMainWindow::createMenus(){ m_pFileMenu = menuBar()->addMenu(tr("&File")); m_pFileMenu->addAction(m_pExitAct); return;}void CMainWindow::createToolBars(){ m_pFileToolBar = addToolBar(tr("File")); m_pFileToolBar->addAction(m_pExitAct); return;}
CApp::~CApp(){ delete m_pGuiManager;}
m_pGuiManager = new CGuiManager(this);
int main(int argc, char *argv[]){ QApplication app(argc, argv); QPushButton hello("Hello world!"); hello.resize(100, 30); hello.show(); return app.exec();}
delete m_pGuiManager
CGuiManager::~CGuiManager(){ //delete m_pMainWindow;}
m_mуWindow->deleteLater();m_mуWindow = 0;