Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt File Dialog Rendered Incorrectly and Crashes

Tags:

c++

visual-c++

qt

I am using the QFileDialog::getOpenFileName function to get a file to open. However, on a client's computer running Windows 7 this either displays a corrupted open file dialog as shown in the screenshot, or crashes the entire application.

Corrupted Dialog

The code I use to open the file dialog is:

void MainWindow::on_action_triggered() {
    auto filename = QFileDialog::getSaveFileName(this, "Generate Report", "", "CSV files (*.csv)");

    if (filename.isEmpty()) {
        return;
    }

    // Do operations on filename...
}

I am using Qt 5.5 with Visual Studio 2013.

like image 308
ajshort Avatar asked Oct 08 '15 05:10

ajshort


3 Answers

The issue in this particular case ended up being an incompatibility between Qt and the Dell Backup and Recovery software installed on the client's computer, which included an incompatible shell extension. The solution I used was to remove the backup and recovery software, but it sounds like namespacing Qt is also an alternative. More information is available in QTBUG-41416.

like image 69
ajshort Avatar answered Nov 14 '22 22:11

ajshort


I'm guessing that there is a problem with directory. This empty string provided as path might be problematic. Try fix this this way:

auto filename = QFileDialog::getSaveFileName(this, 
                                             tr("Generate Report"),
                                             QString(),
                                             tr("CSV files (*.csv)"));
// or this way
auto filename = QFileDialog::getSaveFileName(this,
                                             tr("Generate Report"),
                                             QDir::home().absolutePath(),
                                             tr("CSV files (*.csv)"));
like image 44
Marek R Avatar answered Nov 15 '22 00:11

Marek R


The root of your problem seems to be memory corruption. To find it, install Microsoft Application Verifier and configure your app with Basics\Heaps. You can do it on your own computer, even if the original problem didn't reproduce. After that, try to reproduce the problem, and I guess you will find your memory corruption.

Update
Now that the problem didn't reproduce on your machine and you say the dialog is hung, I suggest the following additional steps (you can do everything yourself in a TeamViewer session to make it easier)

  1. Enable Application Verifier on customer's machine for your EXE. As a side effect, that enables heap tracing.
  2. Capture a (series) of dumps during the hung. Have at least one full dump among the series. You can for example do it with SysInternals Process Explorer. Analyzing them later, you would be able to see what the application is doing. Don't forget to generate and save PDB files (debug information) for your EXE (although I think the hung would be outside your exe).
like image 25
Codeguard Avatar answered Nov 15 '22 00:11

Codeguard