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. Access resources using qrc file

Access resources using qrc file

Scheduled Pinned Locked Moved Solved General and Desktop
c++qrcresource
5 Posts 3 Posters 3.5k 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.
  • M Offline
    M Offline
    Maluna34
    wrote on 8 Mar 2018, 14:09 last edited by
    #1

    Hello ! :)

    I'm currently using a qrc file to load a music file. But when I give the path to an external lib (FMOD), it does not find the file.

    FMOD_System_CreateStream(system, QUrl(":/sounds/ocean.mp3").path().toStdString().c_str(), FMOD_DEFAULT, 0, &sound);   // File not found
     
    QMediaPlayer *player = new QMediaPlayer;
    player->setMedia(QUrl(":/sounds/ocean.mp3"));  // OK
    player->play();
    
    

    Do the paths of type :/prefix/alias work only with Qt classes ??
    Thanks ! ;)

    R 1 Reply Last reply 8 Mar 2018, 14:14
    0
    • M Maluna34
      8 Mar 2018, 14:09

      Hello ! :)

      I'm currently using a qrc file to load a music file. But when I give the path to an external lib (FMOD), it does not find the file.

      FMOD_System_CreateStream(system, QUrl(":/sounds/ocean.mp3").path().toStdString().c_str(), FMOD_DEFAULT, 0, &sound);   // File not found
       
      QMediaPlayer *player = new QMediaPlayer;
      player->setMedia(QUrl(":/sounds/ocean.mp3"));  // OK
      player->play();
      
      

      Do the paths of type :/prefix/alias work only with Qt classes ??
      Thanks ! ;)

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 8 Mar 2018, 14:14 last edited by
      #2

      @Maluna34 said in Access resources using qrc file:

      Do the paths of type :/prefix/alias work only with Qt classes ??

      of course they do only work with Qt.
      It's just an abstraction layer before the actual file access (via Qt classes) happens.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      M 1 Reply Last reply 8 Mar 2018, 14:16
      2
      • R raven-worx
        8 Mar 2018, 14:14

        @Maluna34 said in Access resources using qrc file:

        Do the paths of type :/prefix/alias work only with Qt classes ??

        of course they do only work with Qt.
        It's just an abstraction layer before the actual file access (via Qt classes) happens.

        M Offline
        M Offline
        Maluna34
        wrote on 8 Mar 2018, 14:16 last edited by
        #3

        @raven-worx
        Thanks !! And is it possible to convert them to local paths to be used by other libs ?

        R 1 Reply Last reply 8 Mar 2018, 14:24
        0
        • M Maluna34
          8 Mar 2018, 14:16

          @raven-worx
          Thanks !! And is it possible to convert them to local paths to be used by other libs ?

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 8 Mar 2018, 14:24 last edited by
          #4

          @Maluna34
          since they are compiled into your binary and can only be accessed by Qt classes ... no

          But on what basis do you want to provide the data to other libs?
          For example you could define an interface which returns the binary data of your resource.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pablo J. Rogina
            wrote on 8 Mar 2018, 15:12 last edited by Pablo J. Rogina 3 Aug 2018, 15:12
            #5

            @Maluna34 maybe the qrc file mechanism is not the best approach for what you intend to use; however you only know your actual requirements.
            From documentation about Qt resource system:

            The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.

            so a music file for a whole opera concert is not a suitable candidate for being stored in the qrc file as it ends up into your executable.

            Given that said, you could get the file from the resource and save it somewhere to disk so the external tool can access it.

            QFile::copy(":/sounds/ocean.mp3", "/tmp/ocean.mp3");
            

            you can even use QTemporaryFile to avoid worrying about file naming and deletion.

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            3

            4/5

            8 Mar 2018, 14:24

            • Login

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