Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Updated code from 5.4 to 5.8 and dialog.exec(); gives seg fault



  • Hi All,
    I've updated from 5.4 to 5.8 and when I call one dialogue below it crashes on int ret = dialog.exec(); with a seg fault. Can anyone advise please?
    Thanks

    [code]
    QFileDialog dialog;

    dialog.setOptions(QFileDialog::DontUseNativeDialog ); // with or without this
    
    dialog.setFileMode(QFileDialog::AnyFile);
    dialog.setAcceptMode(QFileDialog::AcceptSave);
    
    /*set the directory*/
    if( get_gamepath().isEmpty( ) )
    {
        dialog.setDirectory(".");
    }
    else
    {
        dialog.setDirectory( get_gamepath( ) );
    }
    
    
    dialog.selectFile( name ); // magic happens here
    
    dialog.setNameFilter("*.xml");
    
    QStringList filters;
    filters << "Game files (*.xml)";
    
    dialog.setNameFilters( filters );
    
    
    int ret = dialog.exec();
    if (ret == QDialog::Accepted)
    {
        qDebug() << dialog.selectedFiles();
        gamefilename = dialog.selectedFiles().at( 0 );
    }
    

    [/code]


  • Lifetime Qt Champion

    Hi,

    Can you show a stack trace of this crash ?



  • Hi,
    the stack is below.
    Thanks.

    [code]
    1 ?? 0x7fffed985d16
    2 ?? 0x7fffed98a44a
    3 ?? 0x7fffed00e3c3
    4 ?? 0x7fffed00e3f9
    5 g_main_context_dispatch 0x7ffff23c4b4d
    6 ?? 0x7ffff23c4f20
    7 g_main_context_iteration 0x7ffff23c4fcc
    8 QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) 0x7ffff63bccbf
    9 QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) 0x7ffff636a9ca
    10 QDialog::exec() 0x7ffff7664a07
    11 Main_Class::save_the_game main_class.cpp 79 0x488c25
    12 GameSimulation_PerfectGame_Dialog::GameSimulation_PerfectGame_Dialog gamesimulation_perfectgame_dialog.cpp 39 0x492d20
    13 MainWindow::on_actionFPerfect_Game_Simulation_triggered mainwindow.cpp 622 0x4163cb
    14 MainWindow::qt_static_metacall moc_mainwindow.cpp 193 0x59c480
    15 MainWindow::qt_metacall moc_mainwindow.cpp 232 0x59c5da
    16 QMetaObject::activate(QObject *, int, int, void * *) 0x7ffff6395564
    17 QAction::triggered(bool) 0x7ffff7486cb2
    18 QAction::activate(QAction::ActionEvent) 0x7ffff7489150
    19 ?? 0x7ffff75e972a
    20 ?? 0x7ffff75f0656
    ... <More>
    [/code]

    The function that causes the crash "int ret = dialog.exec();" is called in 11 Main_Class::save_the_game


  • Lifetime Qt Champion

    Running on Linux ? If so, which distribution ?



  • Yes I running on Lubuntu 14.04


  • Moderators

    Hi, some questions:

    1. What happens if you use QFileDialog::getSaveFileName() instead of creating a custom dialog? http://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName
    2. Is your program doing anything else in the background when you open the dialog?


  • Hi ,
    there's no threads running in the back ground. I tried getSaveFileName but get an error?

    
    
        gamefilename = dialog.getSaveFileName( this, tr("Save File"),
                    "game.xml",
                    tr("Game files (*.xml)"));
    
    

    error

    /home/tony/Dropbox/NewDevelopment/Tools/Game/main_class.cpp:92: error: no matching function for call to ‘QFileDialog::getSaveFileName(Main_Class*, QString, const char [9], QString)’
                     tr("Game files (*.xml)"));
                                             ^
    
    /home/tony/Qt/5.8/gcc_64/include/QtWidgets/qfiledialog.h:225: static QString QFileDialog::getSaveFileName(QWidget*, const QString&, const QString&, const QString&, QString*, QFileDialog::Options)
         static QString getSaveFileName(QWidget *parent = Q_NULLPTR,
                        ^
    

    even if I copy and paste the example I get the error
    eg

    QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
                               "/home/jana/untitled.png",
                               tr("Images (*.png *.xpm *.jpg)"));
    
    

    error

    /home/tony/Dropbox/NewDevelopment/Tools/Game/main_class.cpp:92: error: no matching function for call to ‘QFileDialog::getSaveFileName(Main_Class*, QString, const char [24], QString)’
                                    tr("Images (*.png *.xpm *.jpg)"));
                                                                    ^
    
    /home/tony/Qt/5.8/gcc_64/include/QtWidgets/qfiledialog.h:225: static QString QFileDialog::getSaveFileName(QWidget*, const QString&, const QString&, const QString&, QString*, QFileDialog::Options)
         static QString getSaveFileName(QWidget *parent = Q_NULLPTR,
                        ^
    

  • Lifetime Qt Champion

    Looks like Main_Class is not QWidget based.



  • Hi, My main is a qObject, would this cause the crash in dialog.exec? Or is this just related to getSaveFileName?

    class Main_Class : public QObject
    {
        Q_OBJECT
    public:
        explicit Main_Class(QObject *parent = 0);
    
        void set_name( QString name );
        QString get_name( void );
    

  • Moderators

    @tony67 said in Updated code from 5.4 to 5.8 and dialog.exec(); gives seg fault:

    Or is this just related to getSaveFileName?

    In the example code, this is the parent widget. If you don't have a parent widget, just pass a nullptr.


  • Moderators

    @tony67

    Yep,

    getSaveFileName(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = Q_NULLPTR, Options options = Options())
    

    Usually QWidgets inherit QObject, but not the other way around.

    Either give it a QWidget as parent or, do it as @JKSH said, and give it no parent.



  • Hi,
    did the above with parent, still get the seg fault

         gamefilename = dialog.getSaveFileName( nullptr, tr("Save File"),
                    "game.xml",
                    tr("Game files (*.xml)"));
    

    fault

    1   ??                                                                                                                                                                                        0x7fffed985d16 
    2   ??                                                                                                                                                                                        0x7fffed98a44a 
    3   ??                                                                                                                                                                                        0x7fffed00e3c3 
    4   ??                                                                                                                                                                                        0x7fffed00e3f9 
    5   g_main_context_dispatch                                                                                                                                                                   0x7ffff23c4b4d 
    6   ??                                                                                                                                                                                        0x7ffff23c4f20 
    7   g_main_loop_run                                                                                                                                                                           0x7ffff23c5242 
    8   gtk_dialog_run                                                                                                                                                                            0x7fffed95d6a0 
    9   ??                                                                                                                                                                                        0x7fffee0cd73a 
    10  QDialog::exec()                                                                                                                                                                           0x7ffff766492a 
    11  QFileDialog::getSaveFileUrl(QWidget *, QString const&, QUrl const&, QString const&, QString *, QFlags<QFileDialog::Option>, QStringList const&)                                           0x7ffff7675ecd 
    12  QFileDialog::getSaveFileName(QWidget *, QString const&, QString const&, QString const&, QString *, QFlags<QFileDialog::Option>)                                                           0x7ffff7675f8a 
    13  Main_Class::save_the_game                                                                                                                       main_class.cpp                        90  0x488d53       
    14  GameSimulation_PerfectGame_Dialog::GameSimulation_PerfectGame_Dialog                                                                            gamesimulation_perfectgame_dialog.cpp 39  0x492d66       
    15  MainWindow::on_actionFPerfect_Game_Simulation_triggered                                                                                         mainwindow.cpp                        622 0x41646b       
    16  MainWindow::qt_static_metacall                                                                                                                  moc_mainwindow.cpp                    193 0x59c4c6       
    17  MainWindow::qt_metacall                                                                                                                         moc_mainwindow.cpp                    232 0x59c620       
    18  QMetaObject::activate(QObject *, int, int, void * *)                                                                                                                                      0x7ffff6395564 
    19  QAction::triggered(bool)                                                                                                                                                                  0x7ffff7486cb2 
    20  QAction::activate(QAction::ActionEvent)                                                                                                                                                   0x7ffff7489150 
    ... <More>                                                                                                                                                                                                   
    
    

  • Lifetime Qt Champion

    Might be something Ubuntu 14.04 related. This other thread seems to have a similar crash.



  • Thanks You might be right. Just noticed in Unity Engine when I open a save dialogue in Lubuntu 14.04 it causes a crash as well.
    Can't upgrade either AMD graphics drivers don't work on grater than 14 and the open sources ones are to slow :s


  • Lifetime Qt Champion

    Sounds interesting, can you re-build and test your application with your distribution provided Qt development environment ?



  • If I understand what you mean, the qt downloaded with my distro Qt Creator 3.1.1, Based on Qt 5.4.1 (GCC 4.9.2, 64 bit), works fine.


Log in to reply