Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] Using nested resources in C++/QML files
Forum Updated to NodeBB v4.3 + New Features

[Solved] Using nested resources in C++/QML files

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 3.7k 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.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    From my main C++ code (see below), I'm calling an animation QML file that's in my resources. This is what my main function looks like:

    @
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QDeclarativeView view;
    view.setSource(QUrl("qrc:/MyFiles/animation.qml"));
    view.show();
    return app.exec();
    }
    @

    Inside the animation.qml file, it's using an image that's also a resource file. Here's an abbreviated version of the QML file:

    @
    Rectangle {
    width: 1430; height: 800; color: "lightsteelblue"
    Image {
    source: "qrc:/MyFiles/krlogo.jpg"
    SeqeuntialAnimation {
    running: true
    (a NumberAnimation and a ParallelAnimation)
    }
    }
    }
    @

    The lightsteelblue window for the animation comes up fine, so I know the C++ part is doing its job, but I never see the image or the animation in the window that appears. I know the QML file works fine because when I execute it alone, everything moves as it should. Is there some special trick to calling a resource file from a resource file?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Diph
      wrote on last edited by
      #2

      Just use relative path specified in the qrc:
      @MyFiles/krlogo.jpg@

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Endless
        wrote on last edited by
        #3

        I switched the source in the QML to "/MyFiles/krlogo.jpg" and had no luck. But I then changed it to "/MyFiles/KRLogo.jpg", and it worked. Since when are filespecs case-sensitive?

        Also, why is the title of my post in gray whereas most are in black? Am I on some kind of naughty list? :o)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Diph
          wrote on last edited by
          #4

          I guess unread threads are in black. :)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            Qt resources are always case-sensitive (as are the filesystems on unix/OSX). Windows' file system is the odd man out, being case-insensitive. In practice, it's generally a good rule to assume that filenames are case-sensitive.

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Endless
              wrote on last edited by
              #6

              Thanks for the posts. I've only ever worked in a Windows environment. Very interesting about the others platforms. I'll certainly start paying attention to that!

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                Good deal! Glad it helped.

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  [quote author="mlong" date="1314385199"]Qt resources are always case-sensitive (as are the filesystems on unix/OSX). Windows' file system is the odd man out, being case-insensitive. In practice, it's generally a good rule to assume that filenames are case-sensitive.

                  [/quote]

                  Just for the records
                  Mac OS X HFS+ with standard settings is case insensitive too.

                  One should always use the right case, though. That saves you from trouble later, when you're on case sensitive systems.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  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