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. Trying to play a resource file.

Trying to play a resource file.

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.1k Views 1 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.
  • B Offline
    B Offline
    BowCatShot
    wrote on last edited by
    #1

    I'm trying to play a resource file to no avail.

    The code:

    QString ChimesWaveFile = "/home/nick/QT5Projects/PlayMusic/File-chimes.wav";

    .
    .
    .

        player->setMedia(QUrl::fromLocalFile(ChimesWaveFile));
        player->play();
    

    works just fine. But the code:

    QString ChimesWaveFile = ":/File-chimes.wav";

    .
    .
    .

        player->setMedia(QUrl::fromLocalFile(ChimesWaveFile));
        player->play();
    

    does not work in that nothing plays.

    What am I doing wrong?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      A resource file is not local file. When you use QUrl::fromLocalFile(), it will prepend "file://" to the URL. So in the case of your resource path, the resulting URL will be wrong.

      Use default QUrl constructor (if using Qt 5) or QUrl::fromUserInput() (if using Qt 4).

      (Z(:^

      1 Reply Last reply
      0

      • Login

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