May 17, 2011

Hedge Hedge
Lab Rat
191 posts

[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.

  1. QDesktopServices::openUrl(QUrl("file:///" + QApplication::applicationDirPath()));

EDIT: It only crashes when the target folder is empty.

12 replies

May 17, 2011

Franzk Franzk
Lab Rat
831 posts

I would prefer

  1. QDesktopServices::openUrl(QUrl::fromLocalFile(QApplication::applicationDirPath()));
but I’m not sure if that will prevent the crash.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 17, 2011

Hedge Hedge
Lab Rat
191 posts

Thanks Franzk,

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?

May 17, 2011

Franzk Franzk
Lab Rat
831 posts

Nasty…

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 17, 2011

Hedge Hedge
Lab Rat
191 posts

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.

May 17, 2011

Volker Volker
Ant Farmer
5428 posts

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 :-)

May 17, 2011

Hedge Hedge
Lab Rat
191 posts

You got me :)

No, I’m looking in a subfolder of my application path.

May 17, 2011

Volker Volker
Ant Farmer
5428 posts

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.

May 17, 2011

Hedge Hedge
Lab Rat
191 posts

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.

May 18, 2011

Hedge Hedge
Lab Rat
191 posts

Since it crashes os OSX every time (even if the folder is non-empty) I filed a bug in JIRA:

http://bugreports.qt.nokia.com/browse/QTBUG-19378

May 18, 2011

Volker Volker
Ant Farmer
5428 posts

The snippet from the bugreport works for me. Although, on Windows your path is wrong. These are the right calls:

  1.     QString path = QApplication::applicationDirPath() + "/somefolder";
  2.     QDesktopServices::openUrl(QUrl::fromLocalFile(path));

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.

May 18, 2011

Hedge Hedge
Lab Rat
191 posts

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.

May 18, 2011

Franzk Franzk
Lab Rat
831 posts

Volker’s code works fine for me on Qt 4.7.0, winXP. It seems your crash isn’t related to openUrl()?

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

 
  ‹‹ I can’t Insert a new data to SQLITE      Strange questions about QTableWidget ››

You must log in to post a reply. Not a member yet? Register here!