QFileDialog::getOpenFileName crashes when debugging, apparently caused by project name?
Asked Answered
J

2

5

I've run into a problem that's really confusing me. I'm using Qt Creator 3.1.2, with Qt 5.3 on Windows 7, using the MSVC 10.0 compiler and CDB from Debugging Tools for Windows 8.1. (Not sure if I should be looking for a Windows 7-specific debugger, but I haven't had any issues until now).

The problem: when I try to use QFileDialog::getOpenFileName() while debugging, the program throws an exception.

The inferior stopped because it triggered an exception.

Stopped in thread 0 by: Exception at 0x745f7736, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance).

Release/debug build doesn't matter. If I'm running the debugger, it crashes. If I'm not, it works. I tried a bunch of different things to try to figure out why this was happening - I moved the getOpenFileName to a different part of the program, I tried changing/removing the parameters on the function call, I stripped down basically all my code except the bare minimum required to display this file dialog - a QApplication and a main window that called getOpenFileName() when a menubar item is clicked. Nothing worked.

Then I created a new project that was basically the same thing. Inexplicably, -that- worked. So a whole lot of messing around later, and copying things from my main project until it started crashing again, I ended up finding the problem: apparently, it's the executable name set by "TARGET" in the .pro file. If it's set to PrimeWorldEditor (my application's name), it crashes. If I change it to anything else, it works.

So my first thought was that there were leftover files that share their name with the executable somewhere causing problems. However, clearing out the build folder, rebuilding the project, and anything else doesn't help.

I'm at the point where I've run out of ideas for what could be causing the problem, and I've tried and failed to find via search any other files that either share their name with the executable or point to it. If anyone has any idea what the issue could be, I'd really appreciate the help. I could work around it for now by changing the executable's name, but I'd really like to find out why this is happening and fix it.

EDIT: A few people are asking for code, so here's an example of a program that crashes. Once again, this only crashes when running the debugger with the target executable name set to PrimeWorldEditor. Under other circumstances, it works as expected and opens the getOpenFileName() dialog.

#include <QApplication>
#include <QFileDialog>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QFileDialog::getOpenFileName();
    return 0;
}

I think the issue is likely something related to my setup, so I'm not sure it'll be easily reproducible.

EDIT 2: I wanna add that I did spend a while Googling to try to find any information related to the issue. I did find a couple people who seemed to have the same problem as me, like this post, but there weren't any solutions on those posts.

Jacoby answered 12/8, 2014 at 17:29 Comment(7)
Hi, Do you know where it crashes in the program ? Sometimes it's stupid mistakes ! Do not hesitate to put small parts of your code.Bettyebettzel
It crashes whenever getOpenFileName() is called, regardless of where in the program it is, and the slot functions being called work perfectly if they don't call getOpenFileName(). That, combined with the fact that the exact same code works perfectly with a different executable name, seem to indicate to me there's nothing wrong with the code, which is why I didn't include any code snippets in the post.Jacoby
It's difficult to give good help with just an error message. Please provide some code where getOPenFileName() is called.Favors
I added a code snippet.Jacoby
are you sure it is safe to use QFileDialog::getOpenFileName without the event loop (return a.exec();) ???Coed
I get the same results with the event loop... this is just an example minimalist program that has the issue I'm describing. In any case, pretty sure all you need to use a QFileDialog is having previously constructed a QApplication, which I did. My regular non-stripped-down project does call the event loop.Jacoby
I just tried without exec() and you're right it works but it's not the problem. It's strange that you focus on the name of your executable. Just clean everything, delete build folder and test again. If you create a whole new empty project with only the few lines you wrote, you don't have any problem ?Bettyebettzel
E
3

I had the same problem and the solution was to uninstall git software, which made context menu in windows explorer.

I got the problem that the program crashed in Visual Studio 2013 Debugger when using QFileDialog::getOpenFileName():

Access Violation while reading position 0xFEEEFEEE

It did not crash when I run the program without debugger or when I set the combine Context option in the project configuration -> debugger -> combine with environment = "No".

I re-installed Visual Studio, Qt and nothing helped.

Finally I removed the git-software I have installed the same day and I uninstalled the software; then afterwards the program didn't crash in Debugger anymore.

I am using a Windows 64-bit computer, but run the Qt program with 32 bit. The git software had a context menu in the windows explorer and somehow this interfered with QFileDialog and caused the problem.

Exoteric answered 29/5, 2015 at 11:55 Comment(0)
J
1

Uhhhh wow okay. I noticed DropboxExt_24 in my call stack for some reason. So I uninstalled the Dropbox app, and suddenly, everything is working correctly. Reinstalled it, and everything still works, so problem solved, I guess?

I've been hosting my code on Dropbox to keep it backed up, not sure if that was related to the issue or not.

Jacoby answered 12/8, 2014 at 19:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.