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. Can't open selected file in windows explorer from application

Can't open selected file in windows explorer from application

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 2 Posters 7.4k Views
  • 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.
  • N Offline
    N Offline
    Niagarer
    wrote on 26 Nov 2017, 11:51 last edited by
    #1

    Hi,
    I try to open a file in the explorer (OS independent in the end). That's what I try on windows:

        QStringList args;
        args << "/select," << QDir::toNativeSeparators("G:/test.txt");
        QProcess::startDetached("explorer", args);
    

    This test.txt is definately there, but when I call this, it just opens the explorer, not the selected directory or file.
    What did I miss?
    Thanks for answers!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 26 Nov 2017, 11:56 last edited by
      #2

      Hi
      are u sure the "/select," << comma is correct ?

      N 1 Reply Last reply 26 Nov 2017, 11:57
      0
      • M mrjj
        26 Nov 2017, 11:56

        Hi
        are u sure the "/select," << comma is correct ?

        N Offline
        N Offline
        Niagarer
        wrote on 26 Nov 2017, 11:57 last edited by Niagarer
        #3

        @mrjj
        I took that from
        https://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
        and
        http://lynxline.com/show-in-finder-show-in-explorer/
        Yes, there it seems to work

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 26 Nov 2017, 12:02 last edited by mrjj
          #4

          Ok.
          Its also possible to use Desktop services and do
          QDesktopServices::openUrl(QUrl("file:///home/xx/fileName.pdf"));
          to open it in default app,
          but you seem to want to open explorer and have it selected?
          (which samples is for. not to launch the app for edit. )

          update:
          it works here
          alt text

          it will open folder select the file. as it should.
          (it does not open the file but that is not expected)

          N 1 Reply Last reply 26 Nov 2017, 12:06
          0
          • M mrjj
            26 Nov 2017, 12:02

            Ok.
            Its also possible to use Desktop services and do
            QDesktopServices::openUrl(QUrl("file:///home/xx/fileName.pdf"));
            to open it in default app,
            but you seem to want to open explorer and have it selected?
            (which samples is for. not to launch the app for edit. )

            update:
            it works here
            alt text

            it will open folder select the file. as it should.
            (it does not open the file but that is not expected)

            N Offline
            N Offline
            Niagarer
            wrote on 26 Nov 2017, 12:06 last edited by Niagarer
            #5

            @mrjj
            Yes, I create several text files while runtime and by clicking on a button, I want to open one specific (depending on the button) selected in the explorer (not in a text editor), not in the browser

            update
            well I found a text file, that works (I just tried randomly):

                // this works
                args << "/select," << QDir::toNativeSeparators("C:/Program Files/Autodesk/Maya2018/bin/MTTH.txt");
                QProcess::startDetached("explorer", args);
            

            but yet I could not find any other text file, that works. Not on the G disk, not on the C, that's the only one

            M 1 Reply Last reply 26 Nov 2017, 12:10
            0
            • N Niagarer
              26 Nov 2017, 12:06

              @mrjj
              Yes, I create several text files while runtime and by clicking on a button, I want to open one specific (depending on the button) selected in the explorer (not in a text editor), not in the browser

              update
              well I found a text file, that works (I just tried randomly):

                  // this works
                  args << "/select," << QDir::toNativeSeparators("C:/Program Files/Autodesk/Maya2018/bin/MTTH.txt");
                  QProcess::startDetached("explorer", args);
              

              but yet I could not find any other text file, that works. Not on the G disk, not on the C, that's the only one

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 26 Nov 2017, 12:10 last edited by mrjj
              #6

              @Niagarer
              so it should just open explorer and show file as selected ?

              you code works for me on win 10.
              It will open the drive and have the file selected.

              QStringList args;
                args << "/select," << QDir::toNativeSeparators("c:/degree-angles.png");
                QProcess::startDetached("explorer", args);
              

              Tried a few different file and all types seems to work.

              N 1 Reply Last reply 26 Nov 2017, 12:11
              0
              • M mrjj
                26 Nov 2017, 12:10

                @Niagarer
                so it should just open explorer and show file as selected ?

                you code works for me on win 10.
                It will open the drive and have the file selected.

                QStringList args;
                  args << "/select," << QDir::toNativeSeparators("c:/degree-angles.png");
                  QProcess::startDetached("explorer", args);
                

                Tried a few different file and all types seems to work.

                N Offline
                N Offline
                Niagarer
                wrote on 26 Nov 2017, 12:11 last edited by Niagarer
                #7

                @mrjj
                Ok weird then, I also tried on win 10 ...
                I can't find differences between the files I tried... only MTTH.txt works

                update
                Oh, ok it seems to be a general problem with my system... I also can't open it from cmd like you tried... it opens my dcuments then... So it seems not to be a qt problem

                M 1 Reply Last reply 26 Nov 2017, 12:15
                0
                • N Niagarer
                  26 Nov 2017, 12:11

                  @mrjj
                  Ok weird then, I also tried on win 10 ...
                  I can't find differences between the files I tried... only MTTH.txt works

                  update
                  Oh, ok it seems to be a general problem with my system... I also can't open it from cmd like you tried... it opens my dcuments then... So it seems not to be a qt problem

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 26 Nov 2017, 12:15 last edited by
                  #8

                  @Niagarer
                  All files work here. Even folders.
                  I also tried other drives and so i agree must be something locally
                  in your system. ( no idea what though)

                  N 1 Reply Last reply 26 Nov 2017, 12:19
                  1
                  • M mrjj
                    26 Nov 2017, 12:15

                    @Niagarer
                    All files work here. Even folders.
                    I also tried other drives and so i agree must be something locally
                    in your system. ( no idea what though)

                    N Offline
                    N Offline
                    Niagarer
                    wrote on 26 Nov 2017, 12:19 last edited by Niagarer
                    #9

                    @mrjj
                    Ok, yes I even can't open the MTTH.txt file from cmd, it just opens my documents folder every time...
                    I have no idea... I hope I can fix this
                    Thanks for your help!

                    I can open the files with a notepad, but not with the explorer. So my explorer seems to be sick.
                    I will update anyways when I have a solution

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 26 Nov 2017, 12:21 last edited by mrjj
                      #10

                      Hi
                      For test, try disable any extra virus scanner you have installed.

                      N 1 Reply Last reply 26 Nov 2017, 12:23
                      0
                      • M mrjj
                        26 Nov 2017, 12:21

                        Hi
                        For test, try disable any extra virus scanner you have installed.

                        N Offline
                        N Offline
                        Niagarer
                        wrote on 26 Nov 2017, 12:23 last edited by
                        #11

                        @mrjj
                        Good point,
                        unfortunately doesn't help :/

                        M 1 Reply Last reply 26 Nov 2017, 12:26
                        0
                        • N Niagarer
                          26 Nov 2017, 12:23

                          @mrjj
                          Good point,
                          unfortunately doesn't help :/

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 26 Nov 2017, 12:26 last edited by
                          #12

                          @Niagarer
                          Would have been too easy. ;)

                          did you try with quotes ?
                          explorer.exe /select,"e:\test.txt"
                          (in cmd)

                          N 1 Reply Last reply 26 Nov 2017, 12:29
                          0
                          • M mrjj
                            26 Nov 2017, 12:26

                            @Niagarer
                            Would have been too easy. ;)

                            did you try with quotes ?
                            explorer.exe /select,"e:\test.txt"
                            (in cmd)

                            N Offline
                            N Offline
                            Niagarer
                            wrote on 26 Nov 2017, 12:29 last edited by Niagarer
                            #13

                            @mrjj
                            Yup, unfortunately also no solution... but then it does not open my documents folder, it just open the explorer
                            Slowly but surely it start to get funny

                            update
                            When I try to select, it just opens the explorer, if not, it opens the documents folder

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 26 Nov 2017, 12:34 last edited by
                              #14

                              well it does open docs here too if no /select
                              if i do
                              .. /select,"file that dont exists"
                              it opens "This PC"

                              N 1 Reply Last reply 26 Nov 2017, 12:38
                              0
                              • M mrjj
                                26 Nov 2017, 12:34

                                well it does open docs here too if no /select
                                if i do
                                .. /select,"file that dont exists"
                                it opens "This PC"

                                N Offline
                                N Offline
                                Niagarer
                                wrote on 26 Nov 2017, 12:38 last edited by Niagarer
                                #15

                                @mrjj
                                yes, the weird thing is, that the explorer defiantely knows the file. I even can search in the explorer search line and it finds the file.
                                But as you wrote, from cmd it can't find the file...
                                I can navigate to the right folder on the G drive, it still can't find the file

                                M 1 Reply Last reply 26 Nov 2017, 12:42
                                0
                                • N Niagarer
                                  26 Nov 2017, 12:38

                                  @mrjj
                                  yes, the weird thing is, that the explorer defiantely knows the file. I even can search in the explorer search line and it finds the file.
                                  But as you wrote, from cmd it can't find the file...
                                  I can navigate to the right folder on the G drive, it still can't find the file

                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 26 Nov 2017, 12:42 last edited by
                                  #16

                                  @Niagarer
                                  But its only /select that is broken correct?
                                  if you do other commands it does work?
                                  like
                                  type e:\test.txt

                                  N 1 Reply Last reply 26 Nov 2017, 12:46
                                  0
                                  • M mrjj
                                    26 Nov 2017, 12:42

                                    @Niagarer
                                    But its only /select that is broken correct?
                                    if you do other commands it does work?
                                    like
                                    type e:\test.txt

                                    N Offline
                                    N Offline
                                    Niagarer
                                    wrote on 26 Nov 2017, 12:46 last edited by Niagarer
                                    #17

                                    @mrjj
                                    No, I don't think so.
                                    All the following commands don't work:

                                    // here it says, it could find that file... it is definately there
                                    notepad G:/test.txt
                                    
                                    explorer G:/
                                    
                                    explorer /select G:/test.txt
                                    
                                    M 1 Reply Last reply 26 Nov 2017, 12:57
                                    0
                                    • N Niagarer
                                      26 Nov 2017, 12:46

                                      @mrjj
                                      No, I don't think so.
                                      All the following commands don't work:

                                      // here it says, it could find that file... it is definately there
                                      notepad G:/test.txt
                                      
                                      explorer G:/
                                      
                                      explorer /select G:/test.txt
                                      
                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 26 Nov 2017, 12:57 last edited by
                                      #18

                                      @Niagarer
                                      and g:\ is just another hard drive or partition ?
                                      Like c:\ ?

                                      But it dont work at c:\ either so must be something broken in your windows.

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 26 Nov 2017, 12:58 last edited by mrjj
                                        #19

                                        Oh
                                        in cmd
                                        you must use \ that slash. not / .

                                        Qt makes it possible to use / but windows dont know it natively.

                                        N 1 Reply Last reply 26 Nov 2017, 13:10
                                        1
                                        • M mrjj
                                          26 Nov 2017, 12:58

                                          Oh
                                          in cmd
                                          you must use \ that slash. not / .

                                          Qt makes it possible to use / but windows dont know it natively.

                                          N Offline
                                          N Offline
                                          Niagarer
                                          wrote on 26 Nov 2017, 13:10 last edited by Niagarer
                                          #20

                                          @mrjj
                                          Ok, I got it. Yes G is just another drive and it didn't work on any drive because:
                                          I also noticed this \ and / thing and this was one of my mistakes.
                                          Another thing, why cmd could not find one of my test.txt files I tried to open was that I named it test.txt (so the actual file name was test.txt.txt as my browser told me <facepalm x3>).
                                          And one last thing, that is no less stupid is, that I sent the path from another object and this object did not send the .txt ending. Baad day :D
                                          And I copied the path of some text files from the explorer and tried these, but the \ made it not working.
                                          I thought that

                                          QDir::toNativeSeperators(pathIn);
                                          

                                          would fix \ to / (or \ on windows), but that seems to be wrong. It just takes normal paths with / and translates it to \ on windows http://doc.qt.io/qt-4.8/qdir.html#toNativeSeparators

                                          Thank you very much for you help!

                                          1 Reply Last reply
                                          2

                                          7/21

                                          26 Nov 2017, 12:11

                                          14 unread
                                          • Login

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