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]how to import from the qrc?
QtWS25 Last Chance

[solved]how to import from the qrc?

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 5 Posters 8.2k 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.
  • H Offline
    H Offline
    harlentan
    wrote on last edited by
    #1

    Hi,

    I push the Page into the PageStack use:
    @
    pagestack.push(Qt.resolveUrl("qrc:/qml/page/MyPage"));
    @

    then, in the MyPage.qml:
    @
    import QtQuick 1.0
    import "../ui" as UI
    @

    But it seems that the MyPage cannot find the ui directory.

    If I do not use qrc to load MyPage, the use of import *"../ui" as UI *work perfectly.

    so how to deal with this situation?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      manishsharma
      wrote on last edited by
      #2

      try following

      @import ":/qml/UI" as UI@

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MichK
        wrote on last edited by
        #3

        Maybe you should add your ui folder and its content to a resource file.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          harlentan
          wrote on last edited by
          #4

          [quote author="michal.k" date="1313420616"]Maybe you should add your ui folder and its content to a resource file.[/quote]

          I added it into the qrc, but it didn't work.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            harlentan
            wrote on last edited by
            #5

            [quote author="manishsharma" date="1313420357"]try following

            @import ":/qml/UI" as UI@
            [/quote]

            :(, failed

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MichK
              wrote on last edited by
              #6

              Hmm,
              To be frank I have never imported directories. Maybe add content of the directory to a resource file and access it by specifying resource url.

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

                Could "QDeclarativeEngine::addImportPath":http://doc.qt.nokia.com/4.7/qdeclarativeengine.html#addImportPath possibly help?

                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
                • H Offline
                  H Offline
                  harlentan
                  wrote on last edited by
                  #8

                  [quote author="mlong" date="1313603718"]Could "QDeclarativeEngine::addImportPath":http://doc.qt.nokia.com/4.7/qdeclarativeengine.html#addImportPath possibly help? [/quote]

                  It seems doesn't work with my situation.

                  I just donn't know how to import the component from the qrc

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mbrasser
                    wrote on last edited by
                    #9

                    Hi,

                    It looks like your setup is a bit different from the approach described at http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#managing-resource-files-with-the-qt-resource-system. It might be worth reworking your code to match the structure there, if possible (basically, use qrc when loading the initial file from C++, and relative paths everywhere inside QML). If that doesn't work, I'd suggest filing a bug via http://bugreports.qt.nokia.com

                    Regards,
                    Michael

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      harlentan
                      wrote on last edited by
                      #10

                      [quote author="mbrasser" date="1313707194"]Hi,

                      It looks like your setup is a bit different from the approach described at http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#managing-resource-files-with-the-qt-resource-system. It might be worth reworking your code to match the structure there, if possible (basically, use qrc when loading the initial file from C++, and relative paths everywhere inside QML). If that doesn't work, I'd suggest filing a bug via http://bugreports.qt.nokia.com

                      Regards,
                      Michael[/quote]

                      Hi, thanks for your reply. I have just gotten over it. I use the addImportPath() to regist my import path. and then I can import like this:

                      @
                      //in cpp

                      engine->addImportPath(""qrc:/);

                      //in qml
                      import "qrc:/qml/ui" as UI
                      @
                      At this time, the Qt Creator IDE will surely regard it as a fault that cannot find the path or file.
                      But when recompiled my project, it worked as expected. So, the Qt IDE confused me. Maybe it's
                      a bug of Qt Creator.

                      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