MainWindow.h
#include <QMainWindow>
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
};
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
};
To copy to clipboard, switch view to plain text mode
MainWindow.cpp
#include "MainWindow.h"
{
#ifdef QT_DEBUG
setWindowTitle("DEBUG");
#else
setWindowTitle("RELEASE");
#endif
}
#include "MainWindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
#ifdef QT_DEBUG
setWindowTitle("DEBUG");
#else
setWindowTitle("RELEASE");
#endif
}
To copy to clipboard, switch view to plain text mode
Application.h
#include <QApplication>
class MainWindow;
{
public:
Application(int argc, char** argv);
~Application();
MainWindow* mainWindow() const;
private:
MainWindow* _mainWindow;
};
#include <QApplication>
class MainWindow;
class Application : public QApplication
{
public:
Application(int argc, char** argv);
~Application();
MainWindow* mainWindow() const;
private:
MainWindow* _mainWindow;
};
To copy to clipboard, switch view to plain text mode
Application.cpp
#include "Application.h"
#include "MainWindow.h"
Application
::Application(int argc,
char** argv
) : QApplication(argc, argv
){
_mainWindow = new MainWindow;
}
Application::~Application(){
delete _mainWindow;
_mainWindow = 0;
}
MainWindow * Application::mainWindow() const
{
return _mainWindow;
}
#include "Application.h"
#include "MainWindow.h"
Application::Application(int argc, char** argv) : QApplication(argc, argv)
{
_mainWindow = new MainWindow;
}
Application::~Application(){
delete _mainWindow;
_mainWindow = 0;
}
MainWindow * Application::mainWindow() const
{
return _mainWindow;
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include "Application.h"
#include "MainWindow.h"
int main(int argc, char** argv)
{
Application app(argc, argv);
app.mainWindow()->show();
return app.exec();
}
#include "Application.h"
#include "MainWindow.h"
int main(int argc, char** argv)
{
Application app(argc, argv);
app.mainWindow()->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
The code above run perfectly fine under release build, but will cause SIGSEGV Error everytime under debug build.
My system is Ubuntu 11.04 64-bits, Qt 4.8/4.7.4
Bookmarks