[SOLVED] Unexplained Segmentation Fault with QDialog::show() and QDialog::exec()
-
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();
}
@ -
[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?
-
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.zipI 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).
-
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!
-
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.
-
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.
-
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 :)