Note that there are some explanatory texts on larger screens.

plurals
  1. POCrash/misfunction of QFileDialog in debug builds
    primarykey
    data
    text
    <p>I know this post is quite old, but I'm experiencing the same kind of problem.</p> <p>I'm using Qt 4.6 on Windows 7 64 bits, application is built with Visual Studio 2008.</p> <p>I have the same kind of use of the <code>QFileDialog</code> class. In a slot of one of my widgets I try to open a "browse window" to select a file to open.</p> <p>I've tried all combinations of the following:</p> <ul> <li>Native vs. <code>QFileDialog</code> instance on stack vs. <code>QFileDialog</code> instance on heap.</li> <li>"parent" parameter set as NULL vs. this vs. mainWindow</li> <li><p><code>QFileDialog::DontUseNativeDialog</code> set to <code>true</code> or <code>false</code></p> <pre><code>const int cFILE_OPEN_DLG_TYPE = 0; #define FILE_OPEN_DLG_PARENT NULL //#define FILE_OPEN_DLG_PARENT this //#define FILE_OPEN_DLG_PARENT mMainWindow const bool cFILE_OPEN_DLG_NATIVE = false; void VgQtModelWidget::on_mBrowseButton_clicked() { QString lFilePath; QFileDialog::Options lOptions = (cFILE_OPEN_DLG_NATIVE ? QFileDialog::DontUseNativeDialog : 0); if (cFILE_OPEN_DLG_TYPE == 0) // Heap allocated dialog { QFileDialog* lFileDlg = new QFileDialog (FILE_OPEN_DLG_PARENT); lFileDlg-&gt;setOptions(lOptions); lFileDlg-&gt;setWindowTitle(tr("Open model")); lFileDlg-&gt;setFilter(tr("Model file (*.vsg4)")); if (!lFileDlg-&gt;exec() || !lFileDlg-&gt;selectedFiles().size()) { delete lFileDlg; return; } lFilePath = lFileDlg-&gt;selectedFiles().at(0); delete lFileDlg; } else if (cFILE_OPEN_DLG_TYPE == 1) // Stack allocated version { QFileDialog lFileDlg (FILE_OPEN_DLG_PARENT); lFileDlg.setOptions(lOptions); lFileDlg.setWindowTitle(tr("Open model")); lFileDlg.setFilter(tr("Model file (*.vsg4)")); if (!lFileDlg.exec() || !lFileDlg.selectedFiles().size()) { return; } lFilePath = lFileDlg.selectedFiles().at(0); } else { lFilePath = QFileDialog::getOpenFileName(FILE_OPEN_DLG_PARENT,tr("Open Model File"), tr("."), tr("Model file (*.vsg4)"), 0, lOptions); } QFile lFile (lFilePath); if (lFile.exists()) { // do something with file... } } </code></pre></li> </ul> <p>This works flawless in release builds, but on debug builds here are the results:</p> <h3>Heap allocated dialog</h3> <p>All versions (native/non-native, parent=this/parent=null) <strong>CRASH</strong>.</p> <h3>Stack allocated dialog</h3> <p>All versions (native/non-native, parent=this/parent=null) <strong>CRASH</strong>.</p> <h3>Static helper</h3> <ul> <li>native, whichever parent: getOpenFileName returns an empty string without showing anything </li> <li>native, whichever parent: <strong>CRASH</strong></li> </ul> <p>Thing is, when it is a crash, it is a really ugly one, with the call stack completely messed up. It really looks like some kind debug/non-debug mixup, but I have double-checked that QT_DEBUG is defined and that I link with the debug libraries for Qt.</p> <p>Anyone has a clue ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload