Hi all,

I am currently writing a GUI based application using QT4.1.1. This app will run on X11 and Embedded environments ( using Qtopia Core ).

I am using QT Designer to draw all the app GUI, and I use a QMainWindow as a base for the whole app.

During my development I noticed I was getting seg faults when I was using a QFileWindow. More precisly, the built-in functions provided by QFileWindow ( create dir, erase dir,... ) accessible by the buttons cause EVERY time seg fault when the buttons are hit.

so let me show here a custom implementation I wrote to make that bug appening:

ui_MainWindow.h is autogenerated by QTDesigner then uic:

Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QtCore/QVariant>
  5. #include <QtGui/QAction>
  6. #include <QtGui/QApplication>
  7. #include <QtGui/QButtonGroup>
  8. #include <QtGui/QMainWindow>
  9. #include <QtGui/QMenuBar>
  10. #include <QtGui/QPushButton>
  11. #include <QtGui/QStatusBar>
  12. #include <QtGui/QWidget>
  13.  
  14. class Ui_MainWindow
  15. {
  16. public:
  17. QWidget *centralwidget;
  18. QPushButton *pushButton;
  19. QMenuBar *menubar;
  20. QStatusBar *statusbar;
  21.  
  22. void setupUi(QMainWindow *MainWindow)
  23. {
  24. MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
  25. MainWindow->resize(QSize(800, 600).expandedTo(MainWindow->minimumSizeHint()));
  26. centralwidget = new QWidget(MainWindow);
  27. centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
  28. pushButton = new QPushButton(centralwidget);
  29. pushButton->setObjectName(QString::fromUtf8("pushButton"));
  30. pushButton->setGeometry(QRect(300, 170, 87, 26));
  31. MainWindow->setCentralWidget(centralwidget);
  32. menubar = new QMenuBar(MainWindow);
  33. menubar->setObjectName(QString::fromUtf8("menubar"));
  34. menubar->setGeometry(QRect(0, 0, 800, 26));
  35. MainWindow->setMenuBar(menubar);
  36. statusbar = new QStatusBar(MainWindow);
  37. statusbar->setObjectName(QString::fromUtf8("statusbar"));
  38. statusbar->setGeometry(QRect(0, 581, 800, 19));
  39. MainWindow->setStatusBar(statusbar);
  40. retranslateUi(MainWindow);
  41.  
  42. QMetaObject::connectSlotsByName(MainWindow);
  43. } // setupUi
  44.  
  45. void retranslateUi(QMainWindow *MainWindow)
  46. {
  47. MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
  48. pushButton->setText(QApplication::translate("MainWindow", "PushButton", 0, QApplication::UnicodeUTF8));
  49. Q_UNUSED(MainWindow);
  50. } // retranslateUi
  51.  
  52. };
  53.  
  54. namespace Ui {
  55. class MainWindow: public Ui_MainWindow {};
  56. } // namespace Ui
  57.  
  58. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

here my implementation files:

Qt Code:
  1. // main.cpp
  2.  
  3. #include "CLr4kds.h"
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. QApplication app(argc, argv);
  8. CLr4kds lr4kds;
  9. return app.exec();
  10. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. // CLr4kds.h
  2.  
  3. #ifndef CLR4KDS_H
  4. #define CLR4KDS_H
  5.  
  6. #include <QApplication>
  7. #include <QWidget>
  8. #include <QMessageBox>
  9. #include <QObject>
  10. #include <QDialog>
  11. #include <QtGui>
  12.  
  13. #include "ui_MainWindow.h"
  14.  
  15. class CLr4kds : public QMainWindow, public Ui::MainWindow
  16. {
  17. Q_OBJECT
  18.  
  19. public:
  20. CLr4kds();
  21.  
  22. private:
  23. QMainWindow *window;
  24.  
  25. public slots:
  26.  
  27. virtual void saveAs ();
  28. };
  29.  
  30.  
  31. #endif //CLR4KDS
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. // CLr4kds.cpp
  2.  
  3. #include "CLr4kds.h"
  4.  
  5. CLr4kds::CLr4kds ()
  6. {
  7. window = new QMainWindow;
  8. this->setupUi ( window );
  9.  
  10. // CUSTOM CONNECTIONS
  11. connect ( this->pushButton, SIGNAL ( clicked () ), this, SLOT ( saveAs () ) );
  12.  
  13. window->showMaximized ();
  14.  
  15. }
  16.  
  17. void CLr4kds::saveAs ()
  18. {
  19. QString ret = QFileDialog::getSaveFileName( this );
  20. }
To copy to clipboard, switch view to plain text mode 

This very simple example, has been compiled on diffrent machines with different release of QT 4.1. The error is always the same :

- launch the app
- click on the unique button, a save dialogbox will pop up
- create a directory with the builtin function/button
- try to erase that directory with a right click on it and "Delete"

the app should quit if you do that.

So if someone can tell me where is my mistake when I subclass QMainWindow it would be great.