Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Qt Bug reported] App crashes on QDesktopServices::openUrl(QUrl("file:///C://folder)); if folder is empty
Forum Updated to NodeBB v4.3 + New Features

[Qt Bug reported] App crashes on QDesktopServices::openUrl(QUrl("file:///C://folder)); if folder is empty

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 6.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hedge
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      I would prefer @QDesktopServices::openUrl(QUrl::fromLocalFile(QApplication::applicationDirPath()));@ but I'm not sure if that will prevent the crash.

      "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

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hedge
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          Nasty...

          "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

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hedge
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

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

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

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hedge
                wrote on last edited by
                #7

                You got me :)

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

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  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.

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

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    Hedge
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      Hedge
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        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";
                        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.

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

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          Hedge
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            Franzk
                            wrote on last edited by
                            #13

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

                            "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

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved