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 Updated to NodeBB v4.3 + New Features

[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 last edited by
    #1

    Hi,

    I'm using the 4.7 beta 2 on Windows and I'm having trouble getting one of the tutorials to work. It's the one about creating QML types with C++. Basically, I try to run it and when it gets to QDeclarativeView::setSource, it gives the following error:

    @<Unknown File>: File error for URL file:app.qml@

    setSource is called like so:

    @view.setSource(QUrl::fromLocalFile("app.qml"));@

    and 'app.qml' is definitely present in the same directory as all of the other files in the project - but is not mentioned in the MMP file (should it be?)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brendand
      wrote on 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 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 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 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 last edited by
              #6

              Thanks! That totally works :)

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jdbastardy
                wrote on 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 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 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 last edited by
                      #10

                      peter, thanks for your post! :)

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        frankiefrank
                        wrote on 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