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 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 ! ;)

    raven-worxR 1 Reply Last reply
    0
    • M Maluna34

      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 ! ;)

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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
      2
      • raven-worxR raven-worx

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

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

        raven-worxR 1 Reply Last reply
        0
        • M Maluna34

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

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on 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
          • Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by Pablo J. Rogina
            #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

            • Login

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