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. Get a file to open with my app - a media player
QtWS25 Last Chance

Get a file to open with my app - a media player

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 505 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.
  • H Offline
    H Offline
    hbatalha
    wrote on 30 Aug 2021, 16:00 last edited by hbatalha
    #1

    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

    A 1 Reply Last reply 30 Aug 2021, 16:29
    0
    • H hbatalha
      30 Aug 2021, 16:00

      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

      A Offline
      A Offline
      artwaw
      wrote on 30 Aug 2021, 16:29 last edited by
      #2

      @hbatalha File associations are set in OS. So answer to your question depends on the OS your program will work on.

      For more information please re-read.

      Kind Regards,
      Artur

      H 1 Reply Last reply 31 Aug 2021, 12:54
      1
      • A artwaw
        30 Aug 2021, 16:29

        @hbatalha File associations are set in OS. So answer to your question depends on the OS your program will work on.

        H Offline
        H Offline
        hbatalha
        wrote on 31 Aug 2021, 12:54 last edited by
        #3

        @artwaw I am on windows

        A 1 Reply Last reply 31 Aug 2021, 13:34
        0
        • H hbatalha
          31 Aug 2021, 12:54

          @artwaw I am on windows

          A Offline
          A Offline
          artwaw
          wrote on 31 Aug 2021, 13:34 last edited by
          #4

          @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).

          For more information please re-read.

          Kind Regards,
          Artur

          H 1 Reply Last reply 1 Sept 2021, 12:06
          0
          • A artwaw
            31 Aug 2021, 13:34

            @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).

            H Offline
            H Offline
            hbatalha
            wrote on 1 Sept 2021, 12:06 last edited by
            #5

            @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?

            J A 2 Replies Last reply 1 Sept 2021, 12:26
            0
            • H hbatalha
              1 Sept 2021, 12:06

              @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?

              J Online
              J Online
              JonB
              wrote on 1 Sept 2021, 12:26 last edited by
              #6

              @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.

              1 Reply Last reply
              2
              • H hbatalha
                1 Sept 2021, 12:06

                @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?

                A Offline
                A Offline
                artwaw
                wrote on 1 Sept 2021, 12:28 last edited by
                #7

                @hbatalha To add to what @JonB said - what happens when someone clicks on the file after you've set the association is that your program is being called with a parameter that is the file url. So you have to check parameters upon startup.

                For more information please re-read.

                Kind Regards,
                Artur

                H 1 Reply Last reply 1 Sept 2021, 17:46
                1
                • A artwaw
                  1 Sept 2021, 12:28

                  @hbatalha To add to what @JonB said - what happens when someone clicks on the file after you've set the association is that your program is being called with a parameter that is the file url. So you have to check parameters upon startup.

                  H Offline
                  H Offline
                  hbatalha
                  wrote on 1 Sept 2021, 17:46 last edited by
                  #8

                  @artwaw I have done it. Thank you all for your help and time.

                  H 1 Reply Last reply 1 Sept 2021, 18:30
                  0
                  • H hbatalha
                    1 Sept 2021, 17:46

                    @artwaw I have done it. Thank you all for your help and time.

                    H Offline
                    H Offline
                    hbatalha
                    wrote on 1 Sept 2021, 18:30 last edited by hbatalha 9 Apr 2021, 14:46
                    #9

                    @hbatalha Just to add more info: I find it much better to do the file association right in the installer. In my case I am using Inno Setup on windows.

                    1 Reply Last reply
                    1

                    4/9

                    31 Aug 2021, 13:34

                    • Login

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