DDD里面的错误是这样的,我觉得很奇怪。我原本没有定义statusBar,后来定义了并且加上
statusBar = new QStatusBar;
statusBar-> showMessage(tr("ready"));
还是出错。
Program received signal SIGSEGV, Segmentation fault.
0xf6d91d5e in QMainWindowLayout::statusBar (this=0x9036890) at widgets/qmainwindowlayout.cpp:219
/home/jing/programming/qt-x11-opensource-src-4.0.1/src/gui/widgets/qmainwindowlayout.cpp:219:5963:beg:0xf6d91d5e
此错误发生在点击菜单(比如&Help)然后选择下拉项(比如About)的时候
不知道有没有人发生过这样的情况呢?我开始是怀疑有没有东西没有被初始化,但是好像没有。
代码贴在下面了,希望能有高手指点一二。谢谢了。
- #ifndef _MAINWINDOW_H
 - #define _MAINWINDOW_H
 - #include <QMainWindow>
 - #include <QMenu>
 - #include <QGroupBox>
 - #include <QPushButton>
 - #include <string>
 - #include "renderarea.h"
 - #include "../core/export.h"
 - using std::string;
 - class MainWindow : public QMainWindow {
 -        Q_OBJECT
 - public:
 -        MainWindow();
 - private slots:
 -        void open();
 -        //bool save();
 -        void about();
 - private:
 -        void createActions();
 -        void createMenus();
 -        void createShapeGroupBox();
 -        void createAttributeGroupBox();
 -        
 -        void loadFile(const QString &fullFileName);
 -        //bool saveFile(const QString &fileName);
 -        Scene *currentScene;       
 -        RenderArea *renderarea;
 -        QMenuBar *menuBar;
 -        QStatusBar *statusBar;
 -        QMenu *fileMenu;
 -        QMenu *helpMenu;
 -        QAction *openAct;
 -        //QAction *saveAct;
 -        QAction *aboutAct;
 -        
 -        QGroupBox *shapeGroupBox;
 -        QGroupBox *attributeGroupBox;
 -        
 -        QPushButton *sphereButton;
 -        QPushButton *triangleButton;
 - };
 - #endif //_MAINWINDOW_H
 
- #include <QtGui>
 - #include "mainwindow.h"
 - MainWindow::MainWindow() {
 -        renderarea = new RenderArea;
 -        createActions();
 -        createMenus();
 -        createShapeGroupBox();
 -        createAttributeGroupBox();
 -               
 -        QGridLayout *mainLayout = new QGridLayout;
 -        delete layout(); //clean existing layout
 -        mainLayout->setMenuBar(menuBar);
 -        mainLayout->addWidget(renderarea,0,0,2,1);
 -        mainLayout->addWidget(shapeGroupBox,0,1);
 -        mainLayout->addWidget(attributeGroupBox,1,1);
 -        setLayout(mainLayout);
 -        setWindowTitle(tr("Fray - Frist Ray Tracer"));
 -        statusBar = new QStatusBar;
 -        statusBar-> showMessage(tr("ready"));
 - }
 - void MainWindow::open() {
 -        QString fileName =QFileDialog::getOpenFileName(this);
 -        if (!fileName.isEmpty()) {
 -               loadFile(fileName);
 -        }
 - }
 - /*
 - bool MainWindow::save() {
 - }
 - */
 - void MainWindow::about() {
 -        QMessageBox::about(this, tr("About Fray"), tr("Ray tracer"));
 - }
 - void MainWindow::createActions() {
 -        openAct = new QAction(QIcon("./images/open.png"), tr("&Open..."), this);
 -        openAct->setShortcut(tr("Ctrl+O"));
 -        openAct->setStatusTip(tr("Open an existing scene"));
 -        connect(openAct,SIGNAL(triggered()), this, SLOT(open()));
 -        aboutAct = new QAction(tr("About Fray"),this);
 -        aboutAct->setStatusTip(tr("About this application"));
 -        connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
 - }
 - void MainWindow::createMenus() {
 -        menuBar = new QMenuBar;
 -        fileMenu = menuBar->addMenu(tr("&File"));
 -        fileMenu->addAction(openAct);
 -        menuBar->addSeparator();
 -        helpMenu = menuBar->addMenu(tr("&Help"));
 -        helpMenu->addAction(aboutAct);
 - }
 - void MainWindow::createShapeGroupBox() {
 -        shapeGroupBox = new QGroupBox(tr("Primitive Shapes"));
 -        sphereButton = new QPushButton(tr("Sphere"));
 -        triangleButton = new QPushButton(tr("Triangle"));
 -        
 -        QGridLayout *layout = new QGridLayout;
 -        layout->addWidget(sphereButton,0,0);
 -        layout->addWidget(triangleButton,0,1);
 -        delete shapeGroupBox->layout();
 -        shapeGroupBox->setLayout(layout);
 -        shapeGroupBox->setFixedSize(200,100);
 - }
 - void MainWindow::createAttributeGroupBox() {
 -        attributeGroupBox = new QGroupBox(tr("Attributes"));
 - }
 - void MainWindow::loadFile(const QString &fullFileName) {
 -        currentScene = new Scene(fullFileName);
 -        
 -        QApplication::setOverrideCursor(Qt::WaitCursor);
 -        renderarea->loadScene(currentScene);
 -        QApplication::restoreOverrideCursor();
 -        
 -        //set current file
 - }
 
[ 此贴被XChinux在2005-10-17 02:42重新编辑 ]