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
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 552 Views 2 Watching
  • 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 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

    artwawA 1 Reply Last reply
    0
    • H hbatalha

      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

      artwawA Offline
      artwawA Offline
      artwaw
      wrote on 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
      1
      • artwawA artwaw

        @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 last edited by
        #3

        @artwaw I am on windows

        artwawA 1 Reply Last reply
        0
        • H hbatalha

          @artwaw I am on windows

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on 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
          0
          • artwawA artwaw

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

            JonBJ artwawA 2 Replies Last reply
            0
            • H hbatalha

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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 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

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

                artwawA Offline
                artwawA Offline
                artwaw
                wrote on 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
                • artwawA artwaw

                  @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 last edited by
                  #8

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

                  H 1 Reply Last reply
                  0
                  • H hbatalha

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

                    H Offline
                    H Offline
                    hbatalha
                    wrote on last edited by hbatalha
                    #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

                    • Login

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