Results 1 to 2 of 2

Thread: Segfault with subclassed QMdiSubWindow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2008
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Segfault with subclassed QMdiSubWindow

    I know where the problem is, but i have no idea how to fix it. The problem is located in websubwindow.cpp: when it tries to access the child widgets it segfaults, starting at the first vbox->addWidget().

    The file structure is:
    torah.cpp
    torah.h
    gui/websubwindow.cpp
    gui/websubwindow.h

    websubwindow.cpp
    Qt Code:
    1. #include "websubwindow.h"
    2.  
    3. webSubWindow::webSubWindow(QWidget * parent, Qt::WindowFlags flags)
    4. : QMdiSubWindow(parent, flags)
    5. {
    6. setWindowTitle(tr("Personal"));
    7. setAttribute(Qt::WA_DeleteOnClose);
    8.  
    9. vbox->addWidget(addressLine);
    10. vbox->addWidget(progressBar);
    11. vbox->addWidget(webView);
    12. vbox->addWidget(statusBar);
    13.  
    14. centralWidget->setLayout(vbox);
    15.  
    16. progressBar->setHidden(true);
    17.  
    18. addressLine->setEditText("http://");
    19.  
    20. setWidget(centralWidget);
    21.  
    22. connect(addressLine, SIGNAL(activated(const QString &)), this, SLOT(goToUrl(const QString &)));
    23. //connect(addressLine->lineEdit(), SIGNAL(returnPressed()), this, SLOT(goToUrl()));
    24. }
    25.  
    26. webSubWindow::~webSubWindow()
    27. {
    28. delete centralWidget;
    29. delete vbox;
    30. delete addressLine;
    31. delete progressBar;
    32. delete webView;
    33. delete url;
    34. }
    To copy to clipboard, switch view to plain text mode 

    websubwindow.h
    Qt Code:
    1. #ifndef WEBSUBWINDOW_H
    2. #define WEBSUBWINDOW_H
    3.  
    4. #include <QtGui/QMdiSubWindow>
    5. #include <QtGui/QWidget>
    6. #include <QtGui/QVBoxLayout>
    7. #include <QtGui/QComboBox>
    8. #include <QtGui/QProgressBar>
    9. #include <QtGui/QStatusBar>
    10.  
    11. #include <QtCore/QUrl>
    12.  
    13. #include <QtWebKit/QWebView>
    14.  
    15. class webSubWindow : public QMdiSubWindow
    16. {
    17. Q_OBJECT
    18.  
    19. private:
    20. QWidget *centralWidget;
    21. QVBoxLayout *vbox;
    22. QUrl *url;
    23.  
    24. public:
    25. webSubWindow(QWidget * parent = 0, Qt::WindowFlags flags = 0);
    26. ~webSubWindow();
    27. QComboBox *addressLine;
    28. QProgressBar *progressBar;
    29. QWebView *webView;
    30. QStatusBar *statusBar;
    31.  
    32. private slots:
    33. void goToUrl(const QString &url);
    34. };
    35.  
    36. #endif // WEBSUBWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    torah.cpp
    Qt Code:
    1. #include "torah.h"
    2. #include "ui_torah.h"
    3. #include "gui/websubwindow.h"
    4.  
    5. Torah::Torah(QWidget *parent)
    6. : QMainWindow(parent), ui(new Ui::TorahClass)
    7. {
    8. ui->setupUi(this);
    9.  
    10. ui->action_Refresh->setVisible(false);
    11. ui->action_Stop->setVisible(false);
    12. ui->action_Back->setEnabled(false);
    13. ui->action_Forward->setEnabled(false);
    14.  
    15. connect(ui->actionNew_Tab, SIGNAL(triggered()), this, SLOT(addTab()));
    16. }
    17.  
    18. Torah::~Torah()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void Torah::addTab()
    24. {
    25. webSubWindow *child = new webSubWindow;
    26. //QMdiSubWindow *child = new QMdiSubWindow;
    27. ui->mdiArea->addSubWindow(child);
    28. child->show();
    29. }
    To copy to clipboard, switch view to plain text mode 

    torah.h
    Qt Code:
    1. #ifndef TORAH_H
    2. #define TORAH_H
    3.  
    4. #include <QtGui/QMainWindow>
    5.  
    6. namespace Ui
    7. {
    8. class TorahClass;
    9. }
    10.  
    11. class Torah : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. Torah(QWidget *parent = 0);
    17. ~Torah();
    18.  
    19. private:
    20. Ui::TorahClass *ui;
    21.  
    22. private slots:
    23. void addTab();
    24. };
    25.  
    26. #endif // TORAH_H
    To copy to clipboard, switch view to plain text mode 
    Any help is appreciated; i've been trying many things to try and solve the problem, but i'm getting no where.

  2. #2
    Join Date
    Dec 2007
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Segfault with subclassed QMdiSubWindow

    You have not allocated the memory for progressBar, addressLine etc
    Let your work talk for you

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.