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. SIGSEGV after adding QFileDialog::getOpenFileName to the program
Forum Updated to NodeBB v4.3 + New Features

SIGSEGV after adding QFileDialog::getOpenFileName to the program

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 6 Posters 5.6k Views 2 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.
  • m.sueM m.sue

    @cdwijs

    Hi,

    probably the this pointer is no longer valid when the file dialog goes out of scope. Maybe just try it with a nullptr.

    -Michael.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #6

    @m.sue Why should it not be valid? QFileDialog::getOpenFileName is static and blocking - the execution will continue when the dialog is closed. In the mean time MainWindow cannot be destroyed.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    m.sueM 1 Reply Last reply
    0
    • jsulmJ jsulm

      @m.sue Why should it not be valid? QFileDialog::getOpenFileName is static and blocking - the execution will continue when the dialog is closed. In the mean time MainWindow cannot be destroyed.

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by m.sue
      #7

      I understood that the crash happens after closing the file dialog. I thought maybe even after closing the whole program. Closing the dialog does not mean that the .NET objects behind the scene are freed immediately.
      I had had similar problems on WINDOWS 7 Enterprise but only in the debug version.
      -Michael

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cdwijs
        wrote on last edited by kshegunov
        #8

        I have rebooted my machine, and removed the build folder, and the .user file.
        I have tried both of the following lines, they both crash, after about 2 minutes after the load file dialog is closed:

        fileName = QFileDialog::getOpenFileName(this,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
        fileName = QFileDialog::getOpenFileName(Q_NULLPTR,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
        

        The crash also happens when the dialog is cancelled.
        The crash does not happen when the file open dialog is opened, and kept open.
        The crash does happen when the dialog is opened, cancelled, and then kept open again.

        What can I do to make this work?
        Cheers, Cedric

        [Added code tags ~kshegunov]

        jsulmJ m.sueM 2 Replies Last reply
        0
        • C cdwijs

          I have rebooted my machine, and removed the build folder, and the .user file.
          I have tried both of the following lines, they both crash, after about 2 minutes after the load file dialog is closed:

          fileName = QFileDialog::getOpenFileName(this,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
          fileName = QFileDialog::getOpenFileName(Q_NULLPTR,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
          

          The crash also happens when the dialog is cancelled.
          The crash does not happen when the file open dialog is opened, and kept open.
          The crash does happen when the dialog is opened, cancelled, and then kept open again.

          What can I do to make this work?
          Cheers, Cedric

          [Added code tags ~kshegunov]

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #9

          @cdwijs What else is your app doing?
          @m-sue We are in the native C++ universe here not .Net :-)

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply
          0
          • jsulmJ jsulm

            @cdwijs What else is your app doing?
            @m-sue We are in the native C++ universe here not .Net :-)

            C Offline
            C Offline
            cdwijs
            wrote on last edited by cdwijs
            #10

            @jsulm said in SIGSEGV after adding QFileDialog::getOpenFileName to the program:

            @cdwijs What else is your app doing?
            @m-sue We are in the native C++ universe here not .Net :-)

            @jsulm: I have created the smallest program that shows the problem. Just run it, press the button, and cancel the file dialog. Then after 3 minutes the program crashes. Here is the complete source code:

            #-------------------------------------------------
            #
            # Project created by QtCreator 2017-06-09T14:42:39
            #
            #-------------------------------------------------
            
            QT       += core gui
            
            greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
            
            TARGET = untitled2
            TEMPLATE = app
            
            
            SOURCES += main.cpp\
                    mainwindow.cpp
            
            HEADERS  += mainwindow.h
            
            FORMS    += mainwindow.ui
            
            #ifndef MAINWINDOW_H
            #define MAINWINDOW_H
            
            #include <QMainWindow>
            
            namespace Ui {
            class MainWindow;
            }
            
            class MainWindow : public QMainWindow
            {
                Q_OBJECT
            
            public:
                explicit MainWindow(QWidget *parent = 0);
                ~MainWindow();
            
            private slots:
                void on_pushButton_clicked();
            
            private:
                Ui::MainWindow *ui;
            };
            
            #endif // MAINWINDOW_H
            
            #include "mainwindow.h"
            #include <QApplication>
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
                MainWindow w;
                w.show();
            
                return a.exec();
            }
            
            
            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            
            #include <QFileDialog>
            
            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            
            void MainWindow::on_pushButton_clicked()
            {
                QString fileName;
                fileName = QFileDialog::getOpenFileName(Q_NULLPTR,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
            }
            
            <?xml version="1.0" encoding="UTF-8"?>
            <ui version="4.0">
             <class>MainWindow</class>
             <widget class="QMainWindow" name="MainWindow">
              <property name="geometry">
               <rect>
                <x>0</x>
                <y>0</y>
                <width>400</width>
                <height>300</height>
               </rect>
              </property>
              <property name="windowTitle">
               <string>MainWindow</string>
              </property>
              <widget class="QWidget" name="centralWidget">
               <widget class="QPushButton" name="pushButton">
                <property name="geometry">
                 <rect>
                  <x>40</x>
                  <y>40</y>
                  <width>75</width>
                  <height>23</height>
                 </rect>
                </property>
                <property name="text">
                 <string>PushButton</string>
                </property>
               </widget>
              </widget>
              <widget class="QMenuBar" name="menuBar">
               <property name="geometry">
                <rect>
                 <x>0</x>
                 <y>0</y>
                 <width>400</width>
                 <height>21</height>
                </rect>
               </property>
              </widget>
              <widget class="QToolBar" name="mainToolBar">
               <attribute name="toolBarArea">
                <enum>TopToolBarArea</enum>
               </attribute>
               <attribute name="toolBarBreak">
                <bool>false</bool>
               </attribute>
              </widget>
              <widget class="QStatusBar" name="statusBar"/>
             </widget>
             <layoutdefault spacing="6" margin="11"/>
             <resources/>
             <connections/>
            </ui>
            
            14:44:14: Running steps for project untitled2...
            14:44:14: Starting: "C:\Qt\5.8\mingw53_32\bin\qmake.exe" C:\Users\crldewijs\Documents\untitled2\untitled2.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
            Info: creating stash file C:\Users\crldewijs\Documents\build-untitled2-Desktop-Debug\.qmake.stash
            14:44:15: The process "C:\Qt\5.8\mingw53_32\bin\qmake.exe" exited normally.
            14:44:15: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" qmake_all
            mingw32-make: Nothing to be done for 'qmake_all'.
            14:44:15: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited normally.
            14:44:15: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" 
            C:/Qt/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug
            mingw32-make[1]: Entering directory 'C:/Users/crldewijs/Documents/build-untitled2-Desktop-Debug'
            C:\Qt\5.8\mingw53_32\bin\uic.exe ..\untitled2\mainwindow.ui -o ui_mainwindow.h
            g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled2 -I. -I..\..\..\..\Qt\5.8\mingw53_32\include -I..\..\..\..\Qt\5.8\mingw53_32\include\QtWidgets -I..\..\..\..\Qt\5.8\mingw53_32\include\QtGui -I..\..\..\..\Qt\5.8\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\5.8\mingw53_32\include\QtCore -Idebug -I. -I..\..\..\..\Qt\5.8\mingw53_32\mkspecs\win32-g++  -o debug\main.o ..\untitled2\main.cpp
            g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled2 -I. -I..\..\..\..\Qt\5.8\mingw53_32\include -I..\..\..\..\Qt\5.8\mingw53_32\include\QtWidgets -I..\..\..\..\Qt\5.8\mingw53_32\include\QtGui -I..\..\..\..\Qt\5.8\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\5.8\mingw53_32\include\QtCore -Idebug -I. -I..\..\..\..\Qt\5.8\mingw53_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\untitled2\mainwindow.cpp
            g++ -pipe -fno-keep-inline-dllexport -g -std=gnu++11 -frtti -Wall -Wextra -dM -E -o debug\moc_predefs.h ..\..\..\..\Qt\5.8\mingw53_32\mkspecs\features\data\dummy.cpp
            C:\Qt\5.8\mingw53_32\bin\moc.exe -DUNICODE -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN --include debug/moc_predefs.h -IC:/Qt/5.8/mingw53_32/mkspecs/win32-g++ -IC:/Users/crldewijs/Documents/untitled2 -IC:/Qt/5.8/mingw53_32/include -IC:/Qt/5.8/mingw53_32/include/QtWidgets -IC:/Qt/5.8/mingw53_32/include/QtGui -IC:/Qt/5.8/mingw53_32/include/QtANGLE -IC:/Qt/5.8/mingw53_32/include/QtCore -I. -IC:/Qt/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include -IC:/Qt/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include-fixed -IC:/Qt/Tools/mingw530_32/i686-w64-mingw32/include -IC:/Qt/Tools/mingw530_32/i686-w64-mingw32/include/c++ -IC:/Qt/Tools/mingw530_32/i686-w64-mingw32/include/c++/i686-w64-mingw32 -IC:/Qt/Tools/mingw530_32/i686-w64-mingw32/include/c++/backward ..\untitled2\mainwindow.h -o debug\moc_mainwindow.cpp
            g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled2 -I. -I..\..\..\..\Qt\5.8\mingw53_32\include -I..\..\..\..\Qt\5.8\mingw53_32\include\QtWidgets -I..\..\..\..\Qt\5.8\mingw53_32\include\QtGui -I..\..\..\..\Qt\5.8\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\5.8\mingw53_32\include\QtCore -Idebug -I. -I..\..\..\..\Qt\5.8\mingw53_32\mkspecs\win32-g++  -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp
            g++ -Wl,-subsystem,windows -mthreads -o debug\untitled2.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o  -lmingw32 -LC:\Qt\5.8\mingw53_32\lib C:\Qt\5.8\mingw53_32\lib\libqtmaind.a -LC:\utils\my_sql\my_sql\lib -LC:\utils\postgresql\pgsql\lib -lshell32 C:\Qt\5.8\mingw53_32\lib\libQt5Widgetsd.a C:\Qt\5.8\mingw53_32\lib\libQt5Guid.a C:\Qt\5.8\mingw53_32\lib\libQt5Cored.a 
            mingw32-make[1]: Leaving directory 'C:/Users/crldewijs/Documents/build-untitled2-Desktop-Debug'
            14:44:21: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited normally.
            14:44:21: Elapsed time: 00:07.
            
            kshegunovK 1 Reply Last reply
            0
            • C cdwijs

              I have rebooted my machine, and removed the build folder, and the .user file.
              I have tried both of the following lines, they both crash, after about 2 minutes after the load file dialog is closed:

              fileName = QFileDialog::getOpenFileName(this,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
              fileName = QFileDialog::getOpenFileName(Q_NULLPTR,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
              

              The crash also happens when the dialog is cancelled.
              The crash does not happen when the file open dialog is opened, and kept open.
              The crash does happen when the dialog is opened, cancelled, and then kept open again.

              What can I do to make this work?
              Cheers, Cedric

              [Added code tags ~kshegunov]

              m.sueM Offline
              m.sueM Offline
              m.sue
              wrote on last edited by
              #11

              @cdwijs

              In the backtrace #9 there is a call to IUnknown_QueryService which I assume causes the error, as in #8 in the networkitemfactory dll does not know what to do about it, initiating error handling in ole32.dll.

              This maybe something completely independent of your program, like dll injection via explorer, virus scanner etc.

              -Michael.

              1 Reply Last reply
              0
              • C cdwijs

                @jsulm said in SIGSEGV after adding QFileDialog::getOpenFileName to the program:

                @cdwijs What else is your app doing?
                @m-sue We are in the native C++ universe here not .Net :-)

                @jsulm: I have created the smallest program that shows the problem. Just run it, press the button, and cancel the file dialog. Then after 3 minutes the program crashes. Here is the complete source code:

                #-------------------------------------------------
                #
                # Project created by QtCreator 2017-06-09T14:42:39
                #
                #-------------------------------------------------
                
                QT       += core gui
                
                greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                
                TARGET = untitled2
                TEMPLATE = app
                
                
                SOURCES += main.cpp\
                        mainwindow.cpp
                
                HEADERS  += mainwindow.h
                
                FORMS    += mainwindow.ui
                
                #ifndef MAINWINDOW_H
                #define MAINWINDOW_H
                
                #include <QMainWindow>
                
                namespace Ui {
                class MainWindow;
                }
                
                class MainWindow : public QMainWindow
                {
                    Q_OBJECT
                
                public:
                    explicit MainWindow(QWidget *parent = 0);
                    ~MainWindow();
                
                private slots:
                    void on_pushButton_clicked();
                
                private:
                    Ui::MainWindow *ui;
                };
                
                #endif // MAINWINDOW_H
                
                #include "mainwindow.h"
                #include <QApplication>
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                    MainWindow w;
                    w.show();
                
                    return a.exec();
                }
                
                
                #include "mainwindow.h"
                #include "ui_mainwindow.h"
                
                #include <QFileDialog>
                
                MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                }
                
                MainWindow::~MainWindow()
                {
                    delete ui;
                }
                
                void MainWindow::on_pushButton_clicked()
                {
                    QString fileName;
                    fileName = QFileDialog::getOpenFileName(Q_NULLPTR,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
                }
                
                <?xml version="1.0" encoding="UTF-8"?>
                <ui version="4.0">
                 <class>MainWindow</class>
                 <widget class="QMainWindow" name="MainWindow">
                  <property name="geometry">
                   <rect>
                    <x>0</x>
                    <y>0</y>
                    <width>400</width>
                    <height>300</height>
                   </rect>
                  </property>
                  <property name="windowTitle">
                   <string>MainWindow</string>
                  </property>
                  <widget class="QWidget" name="centralWidget">
                   <widget class="QPushButton" name="pushButton">
                    <property name="geometry">
                     <rect>
                      <x>40</x>
                      <y>40</y>
                      <width>75</width>
                      <height>23</height>
                     </rect>
                    </property>
                    <property name="text">
                     <string>PushButton</string>
                    </property>
                   </widget>
                  </widget>
                  <widget class="QMenuBar" name="menuBar">
                   <property name="geometry">
                    <rect>
                     <x>0</x>
                     <y>0</y>
                     <width>400</width>
                     <height>21</height>
                    </rect>
                   </property>
                  </widget>
                  <widget class="QToolBar" name="mainToolBar">
                   <attribute name="toolBarArea">
                    <enum>TopToolBarArea</enum>
                   </attribute>
                   <attribute name="toolBarBreak">
                    <bool>false</bool>
                   </attribute>
                  </widget>
                  <widget class="QStatusBar" name="statusBar"/>
                 </widget>
                 <layoutdefault spacing="6" margin="11"/>
                 <resources/>
                 <connections/>
                </ui>
                
                14:44:14: Running steps for project untitled2...
                14:44:14: Starting: "C:\Qt\5.8\mingw53_32\bin\qmake.exe" C:\Users\crldewijs\Documents\untitled2\untitled2.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
                Info: creating stash file C:\Users\crldewijs\Documents\build-untitled2-Desktop-Debug\.qmake.stash
                14:44:15: The process "C:\Qt\5.8\mingw53_32\bin\qmake.exe" exited normally.
                14:44:15: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" qmake_all
                mingw32-make: Nothing to be done for 'qmake_all'.
                14:44:15: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited normally.
                14:44:15: Starting: "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" 
                C:/Qt/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug
                mingw32-make[1]: Entering directory 'C:/Users/crldewijs/Documents/build-untitled2-Desktop-Debug'
                C:\Qt\5.8\mingw53_32\bin\uic.exe ..\untitled2\mainwindow.ui -o ui_mainwindow.h
                g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled2 -I. -I..\..\..\..\Qt\5.8\mingw53_32\include -I..\..\..\..\Qt\5.8\mingw53_32\include\QtWidgets -I..\..\..\..\Qt\5.8\mingw53_32\include\QtGui -I..\..\..\..\Qt\5.8\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\5.8\mingw53_32\include\QtCore -Idebug -I. -I..\..\..\..\Qt\5.8\mingw53_32\mkspecs\win32-g++  -o debug\main.o ..\untitled2\main.cpp
                g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled2 -I. -I..\..\..\..\Qt\5.8\mingw53_32\include -I..\..\..\..\Qt\5.8\mingw53_32\include\QtWidgets -I..\..\..\..\Qt\5.8\mingw53_32\include\QtGui -I..\..\..\..\Qt\5.8\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\5.8\mingw53_32\include\QtCore -Idebug -I. -I..\..\..\..\Qt\5.8\mingw53_32\mkspecs\win32-g++  -o debug\mainwindow.o ..\untitled2\mainwindow.cpp
                g++ -pipe -fno-keep-inline-dllexport -g -std=gnu++11 -frtti -Wall -Wextra -dM -E -o debug\moc_predefs.h ..\..\..\..\Qt\5.8\mingw53_32\mkspecs\features\data\dummy.cpp
                C:\Qt\5.8\mingw53_32\bin\moc.exe -DUNICODE -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN --include debug/moc_predefs.h -IC:/Qt/5.8/mingw53_32/mkspecs/win32-g++ -IC:/Users/crldewijs/Documents/untitled2 -IC:/Qt/5.8/mingw53_32/include -IC:/Qt/5.8/mingw53_32/include/QtWidgets -IC:/Qt/5.8/mingw53_32/include/QtGui -IC:/Qt/5.8/mingw53_32/include/QtANGLE -IC:/Qt/5.8/mingw53_32/include/QtCore -I. -IC:/Qt/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include -IC:/Qt/Tools/mingw530_32/lib/gcc/i686-w64-mingw32/5.3.0/include-fixed -IC:/Qt/Tools/mingw530_32/i686-w64-mingw32/include -IC:/Qt/Tools/mingw530_32/i686-w64-mingw32/include/c++ -IC:/Qt/Tools/mingw530_32/i686-w64-mingw32/include/c++/i686-w64-mingw32 -IC:/Qt/Tools/mingw530_32/i686-w64-mingw32/include/c++/backward ..\untitled2\mainwindow.h -o debug\moc_mainwindow.cpp
                g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\untitled2 -I. -I..\..\..\..\Qt\5.8\mingw53_32\include -I..\..\..\..\Qt\5.8\mingw53_32\include\QtWidgets -I..\..\..\..\Qt\5.8\mingw53_32\include\QtGui -I..\..\..\..\Qt\5.8\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\5.8\mingw53_32\include\QtCore -Idebug -I. -I..\..\..\..\Qt\5.8\mingw53_32\mkspecs\win32-g++  -o debug\moc_mainwindow.o debug\moc_mainwindow.cpp
                g++ -Wl,-subsystem,windows -mthreads -o debug\untitled2.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o  -lmingw32 -LC:\Qt\5.8\mingw53_32\lib C:\Qt\5.8\mingw53_32\lib\libqtmaind.a -LC:\utils\my_sql\my_sql\lib -LC:\utils\postgresql\pgsql\lib -lshell32 C:\Qt\5.8\mingw53_32\lib\libQt5Widgetsd.a C:\Qt\5.8\mingw53_32\lib\libQt5Guid.a C:\Qt\5.8\mingw53_32\lib\libQt5Cored.a 
                mingw32-make[1]: Leaving directory 'C:/Users/crldewijs/Documents/build-untitled2-Desktop-Debug'
                14:44:21: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited normally.
                14:44:21: Elapsed time: 00:07.
                
                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #12

                @jsulm said in SIGSEGV after adding QFileDialog::getOpenFileName to the program:

                In the mean time MainWindow cannot be destroyed.

                Actually it can. The blocking QEventLoop::exec is "fake" blocking, it still spins the global event loop, and as consequence Window's message loop.

                @cdwijs
                Try it without using the static overloads to exclude any funny business with the event loop:

                QFileDialog * dialog = new QFileDialog(this, ...);
                // ... setFileNameFilters and such
                dialog->show();
                
                QObject::connect(dialog, &QDialog::rejected, this, [] () {
                    qDebug() << "Canceled ...";
                });
                QObject::connect(dialog, &QDialog::accepted, this, [] () {
                    qDebug() << "Ok clicked ...";
                });
                

                If your problem persists, try setting the dialog to be alien (non-native) and get back with the results of your experiments. Also disable any antivirus stuff which may interfere as @m-sue suggested.

                Read and abide by the Qt Code of Conduct

                C 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  @jsulm said in SIGSEGV after adding QFileDialog::getOpenFileName to the program:

                  In the mean time MainWindow cannot be destroyed.

                  Actually it can. The blocking QEventLoop::exec is "fake" blocking, it still spins the global event loop, and as consequence Window's message loop.

                  @cdwijs
                  Try it without using the static overloads to exclude any funny business with the event loop:

                  QFileDialog * dialog = new QFileDialog(this, ...);
                  // ... setFileNameFilters and such
                  dialog->show();
                  
                  QObject::connect(dialog, &QDialog::rejected, this, [] () {
                      qDebug() << "Canceled ...";
                  });
                  QObject::connect(dialog, &QDialog::accepted, this, [] () {
                      qDebug() << "Ok clicked ...";
                  });
                  

                  If your problem persists, try setting the dialog to be alien (non-native) and get back with the results of your experiments. Also disable any antivirus stuff which may interfere as @m-sue suggested.

                  C Offline
                  C Offline
                  cdwijs
                  wrote on last edited by
                  #13

                  @kshegunov said in SIGSEGV after adding QFileDialog::getOpenFileName to the program:

                  @jsulm said in SIGSEGV after adding QFileDialog::getOpenFileName to the program:

                  In the mean time MainWindow cannot be destroyed.

                  Actually it can. The blocking QEventLoop::exec is "fake" blocking, it still spins the global event loop, and as consequence Window's message loop.

                  @cdwijs
                  Try it without using the static overloads to exclude any funny business with the event loop:

                  QFileDialog * dialog = new QFileDialog(this, ...);
                  // ... setFileNameFilters and such
                  dialog->show();
                  
                  QObject::connect(dialog, &QDialog::rejected, this, [] () {
                      qDebug() << "Canceled ...";
                  });
                  QObject::connect(dialog, &QDialog::accepted, this, [] () {
                      qDebug() << "Ok clicked ...";
                  });
                  

                  If your problem persists, try setting the dialog to be alien (non-native) and get back with the results of your experiments. Also disable any antivirus stuff which may interfere as @m-sue suggested.

                  I have tried some things, using non-native dialog works. It looks like every native dialog fails. See the below code:

                  #include "mainwindow.h"
                  #include "ui_mainwindow.h"
                  
                  #include <QFileDialog>
                  QFileDialog * dialog;
                  #include <QDebug>
                  
                  
                  MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::MainWindow)
                  {
                      dialog = new QFileDialog();
                      QObject::connect(dialog,&QFileDialog::fileSelected,this, [] () {qDebug()<<"fileselected";}); //fires on pushbutton 2 dialog
                      ui->setupUi(this);
                  }
                  
                  MainWindow::~MainWindow()
                  {
                      delete ui;
                  }
                  
                  void MainWindow::on_pushButton_clicked()
                  {
                      QString fileName;
                      fileName = QFileDialog::getOpenFileName(Q_NULLPTR,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)"); //sigseg after 2 minutes
                  }
                  
                  void MainWindow::on_pushButton_2_clicked()
                  {
                      dialog->show(); //no crash (tested 9 minutes), looks non-native
                  }
                  
                  
                  
                  void MainWindow::on_pushButton_3_clicked()
                  {
                      QString fileName;
                      fileName = dialog->getOpenFileName(Q_NULLPTR,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)"); //sigseg after 2 minutes
                  }
                  
                  void MainWindow::on_pushButton_4_clicked()
                  {
                      QString fileName;
                      fileName = dialog->getOpenFileName(); //sigseg after 2 minutes
                  }
                  
                  
                  
                  void MainWindow::on_pushButton_5_clicked()
                  {
                      QString fileName;
                      fileName = QFileDialog::getOpenFileName(Q_NULLPTR,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)",Q_NULLPTR,QFileDialog::DontUseNativeDialog); //no crash, looks non-native
                  }
                  
                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Rondog
                    wrote on last edited by
                    #14

                    I don't know if this is helpful or not but I ran into a problem a few years back that reminds me of this. A (non-Qt) software I dealt with would crash every time the the user would access the file dialogs (open, save) and it seemed to happen only to certain people. If files were loaded from the recent file list everything was fine. Everything worked until you tried to do something with the file dialogs.

                    The problem turned out to be a name collision of a DLL and Office 2013. With Office 2013 installed everytime the open or save dialog was called and there was a DLL present with a name it thought was somehow assocated with Office 2013 the result was a crash. The solution this (rather large) software company came up with was to rename their DLL file (lol).

                    First I am assuming your program would work on a clean install of Windows 7 with nothing else installed. I have never had this kind of problem using the Qt file dialogs (not like this at least) so I suspect this would be true. I have not used Qt 5.8.x but 5.6.x does not have this problem on Win7.

                    1 Reply Last reply
                    0
                    • C cdwijs

                      Hi All,

                      I'm writing a program that does some processing on a file. After I add this line to the application I get segmentation faults. The fault is not immediately after clicking the button, but it comes after a few minutes. How can I solve this?

                      fileName = QFileDialog::getOpenFileName(this,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
                      

                      Versions:

                      Windows 7 Enterprise SP1 64 bit
                      Qt creator 4.1.0 Based on Qt 5.7.0 (MSVC 2013, 32 bit)
                      Qt 5.8.0 MinGW 5.3.0 32 bit 
                      

                      Full program:

                      #define EDIT_MARKER "This file was edited by 3803829-DXF-Text-Resizer"
                      
                      #include "mainwindow.h"
                      #include "ui_mainwindow.h"
                      
                      #include <QFileDialog>
                      #include <QDebug>
                      
                      MainWindow::MainWindow(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::MainWindow)
                      {
                          ui->setupUi(this);
                      }
                      
                      MainWindow::~MainWindow()
                      {
                          delete ui;
                      }
                      
                      void MainWindow::on_pushButton_clicked()
                      {
                          QString fileName;
                          fileName = QFileDialog::getOpenFileName(this,tr("Open File"),"","Dxf Files(*.dxf);;All files(*.*)");
                      }
                      
                      joeQJ Offline
                      joeQJ Offline
                      joeQ
                      wrote on last edited by
                      #15

                      @cdwijs Hi, friend, welcome.

                      did you try add QFileDialog::DontUseNativeDialog ?

                      i got crash problem in my windows system before . I used the Qt Don't Native Dialog, It worked out. I guess it was the Permission issues. sometime, use the native dialog, it will crashed. but sometimes, it also can worked well.

                      
                      #ifdef USE_NATIVE_DIALOG
                          path = QFileDialog::getOpenFileName(this,tr("select file"), lastDir,FILE_FILTER, 0,QFileDialog::DontUseNativeDialog );
                      #else
                          path = QFileDialog::getOpenFileName(this,tr("select file"), lastDir, FILE_FILTER);
                      #endif
                      

                      Just do it!

                      1 Reply Last reply
                      1

                      • Login

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