Get a file to open with my app - a media player
-
So I created a media player using libvlc and I would like to get a media file open with it, like every media player app.
I want to know how to do it with Qt. The only info about this I found was this one but in the example there the ATOM keyword is not recognized in the G searches only info about the Atom ide I could find.Edit: I am on windows
-
So I created a media player using libvlc and I would like to get a media file open with it, like every media player app.
I want to know how to do it with Qt. The only info about this I found was this one but in the example there the ATOM keyword is not recognized in the G searches only info about the Atom ide I could find.Edit: I am on windows
-
@hbatalha File associations are set in OS. So answer to your question depends on the OS your program will work on.
-
@hbatalha You need to use Windows docs to learn how to do it, i.e. https://docs.microsoft.com/en-gb/windows/win32/shell/fa-sample-scenarios?redirectedfrom=MSDN
For accessing Windows Registry you can use QSettings (safest way).
@artwaw I did that, following this article.. The main code below:
void checkWinRegistry() { QString val; QString exePath = qApp->applicationFilePath(); exePath.replace("/", "\\"); QSettings regType("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc", QSettings::NativeFormat); QSettings regIcon("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\DefaultIcon", QSettings::NativeFormat); QSettings regShell("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\Shell\\Open\\Command", QSettings::NativeFormat); /** . means default value, you can also use the "Default" string */ if("" != regType.value(".").toString()){ regType.setValue(".",""); } /** 0 使用当前程序内置图标 */ val = exePath + ",0"; if(val != regIcon.value(".").toString()){ regIcon.setValue(".",val); } val = exePath + " \"%1\""; if(val != regShell.value(".").toString()){ regShell.setValue(".",val); } }
But I didn't understand the code quite well. Am I supposed to do that with every extension the app supports? Also I couldn't figure out what to do next, how to actually get the file urls into my code for my app to use them?
-
@artwaw I did that, following this article.. The main code below:
void checkWinRegistry() { QString val; QString exePath = qApp->applicationFilePath(); exePath.replace("/", "\\"); QSettings regType("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc", QSettings::NativeFormat); QSettings regIcon("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\DefaultIcon", QSettings::NativeFormat); QSettings regShell("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\Shell\\Open\\Command", QSettings::NativeFormat); /** . means default value, you can also use the "Default" string */ if("" != regType.value(".").toString()){ regType.setValue(".",""); } /** 0 使用当前程序内置图标 */ val = exePath + ",0"; if(val != regIcon.value(".").toString()){ regIcon.setValue(".",val); } val = exePath + " \"%1\""; if(val != regShell.value(".").toString()){ regShell.setValue(".",val); } }
But I didn't understand the code quite well. Am I supposed to do that with every extension the app supports? Also I couldn't figure out what to do next, how to actually get the file urls into my code for my app to use them?
@hbatalha said in Get a file to open with my app - a media player:
Am I supposed to do that with every extension the app supports?
Yep!
At least that's the simplest. Windows Registry file associations also a supports "file types", like "source files" or similar with multiple file extensions as a group, but it's simplest to just do it for each extension explicitly I think.
-
@artwaw I did that, following this article.. The main code below:
void checkWinRegistry() { QString val; QString exePath = qApp->applicationFilePath(); exePath.replace("/", "\\"); QSettings regType("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc", QSettings::NativeFormat); QSettings regIcon("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\DefaultIcon", QSettings::NativeFormat); QSettings regShell("HKEY_CURRENT_USER\\SOFTWARE\\Classes\\.abc\\Shell\\Open\\Command", QSettings::NativeFormat); /** . means default value, you can also use the "Default" string */ if("" != regType.value(".").toString()){ regType.setValue(".",""); } /** 0 使用当前程序内置图标 */ val = exePath + ",0"; if(val != regIcon.value(".").toString()){ regIcon.setValue(".",val); } val = exePath + " \"%1\""; if(val != regShell.value(".").toString()){ regShell.setValue(".",val); } }
But I didn't understand the code quite well. Am I supposed to do that with every extension the app supports? Also I couldn't figure out what to do next, how to actually get the file urls into my code for my app to use them?
-