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] QDeclarativeView::setSource not working?
Forum Update on Tuesday, May 27th 2025

[Solved] QDeclarativeView::setSource not working?

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 7 Posters 10.9k 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
    brendand
    wrote on 24 Aug 2010, 10:41 last edited by
    #2

    Hmm, it seems that using an absolute path works - I guess this might be a bug? Surely it should lookup a qml file the same as it does an image?

    @view.setSource(QUrl::fromLocalFile("/Qt/projects/PieChart/app.qml"));@

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on 24 Aug 2010, 11:34 last edited by
      #3

      try to put your qml file near binary file and try relative path.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        brendand
        wrote on 25 Aug 2010, 09:25 last edited by
        #4

        So how would I do that in Windows? When building the project, how do I 'export' the QML file to the same location as the binary?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aalpert
          wrote on 26 Aug 2010, 01:29 last edited by
          #5

          An easier solution is to put the QML file into the binary using Qt's resource system. Then you can access it as ":/app.qml" and don't have to worry about placement of the file.

          If app.qml references other QML files, they will also need to be compiled in as resources, and with the same relative path as they have now.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            brendand
            wrote on 26 Aug 2010, 09:01 last edited by
            #6

            Thanks! That totally works :)

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jdbastardy
              wrote on 23 Sept 2010, 13:14 last edited by
              #7

              [quote author="aalpert" date="1282786194"]
              If app.qml references other QML files, they will also need to be compiled in as resources, and with the same relative path as they have now.[/quote]

              Just what I needed to know. Thank you!

              http://mattias-cibien.co.cc

              • Prepare for Qt consequences.
              1 Reply Last reply
              0
              • P Offline
                P Offline
                peter
                wrote on 13 Oct 2010, 14:26 last edited by
                #8

                Hi,

                with QT 4.7 beta 2: I used a Declarative View to embed a QML GUI in the C++ application - which was working OK. After I installed QT 4.7 Release 2010.05 I have the following problem (I did not change the code):

                QDeclarativeComponent: Component is not ready
                (<Unknown File>: File error for URL file:///C:/Users/home/git/linuxapp/src/bin/:/qml/gui.qml)

                It is part of the resources and was working with 4.7 beta 2:
                QDeclarativeComponent component(_engine, QUrl::fromLocalFile(":/qml/gui.qml"));

                Now it tries somehow to load the qml-file directly from the working directory. If I change it to:
                QDeclarativeComponent component(_engine, QUrl::fromLocalFile("gui.qml"));
                it works if I place the qml-file there - but I need to have it in the binary application as a ressource - not in a separate qml file.

                Did anybody experience the same problems? How can I make QT 4.7 2010.05 using my ressource file? Tried it on LINUX with cmake and also on Windows using the creator 2.0.1.

                Peter

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  peter
                  wrote on 14 Oct 2010, 07:15 last edited by
                  #9

                  tried it with:

                  QDeclarativeComponent component(_engine, QUrl("qrc:/qml/gui.qml"));

                  this works ;-)

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Shaci
                    wrote on 19 May 2011, 22:24 last edited by
                    #10

                    peter, thanks for your post! :)

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      frankiefrank
                      wrote on 3 Oct 2011, 11:50 last edited by
                      #11

                      I thought this didn't apply to me because I wasn't using resources, but this (using QUrl) in fact did the trick! Thank you!

                      "Roads? Where we're going, we don't need roads."

                      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