Hi! I am making a music player and I want to make the mp3 files open my app with chosen file?
Hi! I am making a music player and I want to make the mp3 files open my app with chosen file?
If this is about registering your application with the system's type registry then this is not Qt related, you'll need to research the target platform's system for that.
If this is about handling commandline arguments, then say so.
Cheers,
_
Not Qt but every application. Read about commandline arguments in C/C++ applications.
If you are talking about something like double-clicking on an mp3 file name in Windows Explorer, and having Windows launch your Qt program to play the file, then you need to do two things:How would qt understand where the file is
1 - Set up an association in Windows that associates files with the extension ".mp3" with your Qt program's EXE file. (There is certainly something similar in other operating systems).
2 - In your Qt program's main() function, you have to look at the arguments to main(): "argc" is the count of the number of arguments on the command line, and is always at least 1. argv[] is an array of pointers to character strings. argv[0] is always the full command line (for example "MyProgram mysong.mp3"). If argc > 1, then argv[1] points to the first argument ("mysong.mp3"), and so forth.
3 - If you find that argc > 1, then you extract argv[1], and pass it into the mp3 playing part of your program. If your program normally opens files interactively (i.e. using QFileDialog or something like that), then the method you'll want to call is probably the same one you would call when the user selects a file from the dialog. The string passed in as argv[1] is almost certainly the full path to the file, not just the filename, so you'll know exactly where the file lives.
The association you set up in Windows (or whatever) takes care of starting your program for you, because that's how associations work. Once your program starts, you have to determine if t was started manually by the user with no filename (argc = 1) or by the operating system in response to a double-click on a filename (argc = 2).
Bookmarks