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. Updated code from 5.4 to 5.8 and dialog.exec(); gives seg fault

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 4 Posters 4.5k Views 3 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.
  • T Offline
    T Offline
    tony67
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you show a stack trace of this crash ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • T Offline
        T Offline
        tony67
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Running on Linux ? If so, which distribution ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tony67
            wrote on last edited by
            #5

            Yes I running on Lubuntu 14.04

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              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?

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tony67
                wrote on last edited by tony67
                #7

                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,
                                    ^
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Looks like Main_Class is not QWidget based.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tony67
                    wrote on last edited by
                    #9

                    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 );
                    
                    JKSHJ J.HilkJ 2 Replies Last reply
                    0
                    • T tony67

                      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 );
                      
                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #10

                      @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.

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      1 Reply Last reply
                      1
                      • T tony67

                        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 );
                        
                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #11

                        @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.


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          tony67
                          wrote on last edited by
                          #12

                          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>                                                                                                                                                                                                   
                          
                          
                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

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

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            1
                            • T Offline
                              T Offline
                              tony67
                              wrote on last edited by
                              #14

                              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

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

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

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  tony67
                                  wrote on last edited by
                                  #16

                                  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.

                                  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