[Qt Bug reported] App crashes on QDesktopServices::openUrl(QUrl("file:///C://folder)); if folder is empty
For some reasons my application crashes when I execute the following line.
@QDesktopServices::openUrl(QUrl("file:///" + QApplication::applicationDirPath()));@
EDIT: It only crashes when the target folder is empty.
I would prefer @QDesktopServices::openUrl(QUrl::fromLocalFile(QApplication::applicationDirPath()));@ but I'm not sure if that will prevent the crash.
I didn't have to try it because it wasn't crashing anymore.
The only difference was that this time there was a file inside the folder.
So it is crashing when the folder is empty.
What kind of obscure bug is that?
I changed thread-title and first post.
This could be some Qt-Bug.
The obvious workaround is putting a file into that folder or checking if it's empty beforehand.
A real solution would be better though.
Everything works for me (Qt 4.7.3/MinGW/Windows Vista)
At least the directory pointed to by applicationDirPath() should not be empty - your .exe lives there :-)
You got me :)
No, I'm looking in a subfolder of my application path.
It works for an empty path for me too, Explorer shows up.
If I give it a non-existent directory, nothing happens, no explorer shows up, no crash either.
It shows up for me too, just crashes in release-mode.
In debug-mode it shows up and doesn't crash, but if I click again on the button (executes the code again) it crashes.
Since it crashes os OSX every time (even if the folder is non-empty) I filed a bug in JIRA:
The snippet from the bugreport works for me. Although, on Windows your path is wrong. These are the right calls:
QString path = QApplication::applicationDirPath() + "/somefolder";
You will hardly ever need native separators in Qt world.
In either case, I do not have crashes neither on windows nor on the mac.
Thanks for correcting me.
Since I use the pre-built SDK (not the obscure Frankenstein-Qt-build experiments from the other thread) I think it is worth a bugreport.
The funny thing is that the directory opens, then my application crashes. I added this detail to the Bugreport.
Volker's code works fine for me on Qt 4.7.0, winXP. It seems your crash isn't related to openUrl()?