Skip to content

33319 - Make PlatformInteractive.RevealInFileBrowser properly invoke Windows Explorer to select the file#13

Merged
igorkorsukov merged 1 commit into
musescore:mainfrom
krasko78:33319-PlatformInteractiveRevealInFileBrowserDoesNotSelectTheFile
May 12, 2026
Merged

33319 - Make PlatformInteractive.RevealInFileBrowser properly invoke Windows Explorer to select the file#13
igorkorsukov merged 1 commit into
musescore:mainfrom
krasko78:33319-PlatformInteractiveRevealInFileBrowserDoesNotSelectTheFile

Conversation

@krasko78
Copy link
Copy Markdown
Contributor

@krasko78 krasko78 commented May 9, 2026

First PR to resolve MuseScore/33319. Then a second PR will be created to update the submodule.

The problem here is that PlatformInteractive::RevealInFileBrowser is passing explorer /select,filename as the program to start specifying no command line arguments. QProcess performs some proccessing of the program string: namely, on Windows it replaces any forward slashes "/" with backslashes "\". So the program to start ends up being explorer \select,filename. Note: the forward slash before select becomes a backslash and as a result Windows explorer does not recognize it and does not select the file (but properly opens the containing folder).

Therefore the solution at first glance is to pass only explorer as the program to start and pass /select,filename as a command line argument (the second parameter to QProcess::startDetached).

There is another hidden problem - that filename must be enclosed in double quotes so that paths and file names with spaces (and possibly other special characters) be processed correctly (as part of the filename and not as other command line prameters). This leads to another problem: QProcess also processes the command-line parameters and if a parameter contains a double quote, it add a backslash ("\") before the quote and encloses the entire parameter in double quotes. So the argument /select,"filename" is turned into "/select,\"filename\"" which again is not what Windows Explorer expects.

The solution is to pass /select,"filename" in nativeArguments. nativeArguments is a QProcess property containing command-line arguments that QProcess just appends unprocessed to the other arguments (that it pre-processes). The use of nativeArguments requires that we create a QProcess instance - the native arguments cannot be set in any static method of QProcess.

Summary of changes:

  1. The program to start becomes "explorer". I've changed it to "explorer.exe".
  2. The only argument is /select,"filename" (filename enclosed in double quotes).
  3. The static method QProcess::startDetached can no longer be used because the argument must be passed via the nativeArguments property (so the argument is not altered in any way).

QProcess class documentation

  • I signed the CLA
  • The title of the PR describes the problem it addresses
  • Each commit's message describes its purpose and effects, and references the issue it resolves
  • If changes are extensive, there is a sequence of easily reviewable commits
  • The code in the PR follows the coding rules
  • There are no unnecessary changes
  • The code compiles and runs on my machine, preferably after each commit individually
  • I created a unit test or vtest to verify the changes I made (if applicable)

@krasko78 krasko78 changed the title 33319 - Make PlatformInteractive.RevealInFileBrowser properly invoke Windows Explorer 33319 - Make PlatformInteractive.RevealInFileBrowser properly invoke Windows Explorer to select the file May 9, 2026
@igorkorsukov igorkorsukov merged commit 72876d3 into musescore:main May 12, 2026
1 check passed
@krasko78 krasko78 deleted the 33319-PlatformInteractiveRevealInFileBrowserDoesNotSelectTheFile branch May 16, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Win] PlatformInteractive::revealInFileBrowser does not select the file in Windows explorer

2 participants