Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Unexplained Segmentation Fault with QDialog::show() and QDialog::exec()
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Unexplained Segmentation Fault with QDialog::show() and QDialog::exec()

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 14.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    powerofpi
    wrote on last edited by
    #4

    Here is the relevant part of my main window code... I'm registering a generateNew slot to receive signals triggered by a new action. Then in a dock widget, I have a button press registered to trigger the new action, causing me to enter my generateNew() slot, where then the seg fault is always occurring on the call to exec(). Could there be a problem with a button press in a dock widget triggering an action and causing a dialog window in the main widget?

    @
    #include "mainwindow.h"
    #include <QDesktopWidget>
    #include <QApplication>
    #include <QResizeEvent>
    #include "engine/engine.h"
    #include "storage/storage.h"
    #include "gui/actionmanager.h"

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    {
    //Test something manually
    //test();

    //Create actions
    createActions();
    
    //Create window internals
    createMainSceneAndView();
    
    //Create dock windows
    createDockWindows();
    
    //Additional Settings for this Window
    configureWindow();
    
    restoreSettings();
    
    show();
    

    }
    void MainWindow::createActions(){

    ActionManager::generateNewAction = new QAction(this);
    connect(ActionManager::generateNewAction, SIGNAL(triggered()), this, SLOT(generateNew()));
    

    }
    void MainWindow::generateNew(){
    qDebug() << "MainWindow got generate new event.";

    //Create a dialog window to get the requested difficulty
    this->generateNewDialog = new GenerateNewDialog(this);
    connect(this->generateNewDialog, SIGNAL(difficultySelected(int)), this, SLOT(generationDifficultySelected(int)));
    
    this->generateNewDialog->exec&#40;&#41;;
    

    }
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #5

      [quote author="Volker" date="1298677672"]Can you create a short, complete, compilable and running program that demonstrates the error. Put everything into a ZIP (including the project file) and put it on dropbox or something else. We then can grab the sources and have a look.[/quote]

      What's so hard to understand about these sentences?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        powerofpi
        wrote on last edited by
        #6

        No need to be rude, nothing is hard about it. I just told you, I attempted to do so, and the same dialog window was called in the same way but worked with no problem. Therefore, it is only logical that there is something else wrong in my main code.

        Here is a link to the simple example I made where the code DOES work:
        http://dl.dropbox.com/u/7027137/dialog_example.zip

        I will post a link to my main project where the dialog does NOT work as soon as it finishes uploading to my public dropbox folder (I'm somewhere where the Internet connection is very poor).

        1 Reply Last reply
        0
        • P Offline
          P Offline
          powerofpi
          wrote on last edited by
          #7

          Alright, I trimmed some fat and it's done uploading:

          http://dl.dropbox.com/u/7027137/git_code.zip

          Specifically, the "new" button in the GameTab class should trigger the new game action, which should spawn the dialog window (which instead is seg-faulting). If you can figure out why it seg faults here but not in my other simple example, I'd be quite grateful!

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #8

            I'll have a look at it - stay tuned.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #9

              It runs on Mac OS X with Qt 4.7.1 without problems (once I fixed a compiler error in GUI::event(): m_mainWindow is not present there). Although it crashes on application shutdown, because you add one single instance of a widget multiple times (eg. QSpacerItem *gap in settingstab.cpp).

              I'll have a look at Linux once I have a recent Kubuntu box running.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #10

                Next serious error: The signatures of the following methods are wrong.

                @
                class GUI : public QApplication
                {
                public:
                static GUI* getInstance(int argc, char **argv){

                GUI(int argc, char ** argv);
                

                };
                @

                Please read the API docs on "QCoreApplication::QCoreApplication() ":http://doc.qt.nokia.com/4.7-snapshot/qcoreapplication.html#QCoreApplication and adhere to the warning there - it's not without reason! And of course change the method and constructor signatures accordingly. It could be that this is the reason for the application crash on Linux.

                Second: For what you want to do, a QApplication subclass is not necessary (look at event filters!). The code inside your constructor can easily be moved to the main() function.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  powerofpi
                  wrote on last edited by
                  #11

                  Thank you very much for taking the time to look at it! I will use your feedback going forward and hopefully resolve the segmentation fault.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    powerofpi
                    wrote on last edited by
                    #12

                    You got it, Volker. Passing an int instead of int & to the constructor was causing the crash.

                    I have my own reasons for subclassing QApplication and keeping that code out of the main method. I actually am going to have 5 high-level components, of which the GUI is just one, the goal being to keep things modular and easily maintainable. Also, getInstance() doesn't have anything to do with QApplication::instance(). It is just simply meant to make the GUI class a singleton.

                    Anyway, thanks again for your help. Problem solved :)

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #13

                      Glad to hear that it was that easy :-)

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved