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. Multiple directories in QML project
Forum Updated to NodeBB v4.3 + New Features

Multiple directories in QML project

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.5k 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.
  • A Offline
    A Offline
    AleksandarJovanov
    wrote on last edited by
    #1

    Hello qt devs.I am kinda new to this, but I really like QML so I decided to use Qt and QML for my next project.
    I plan on making a complex and relatively big application using QML and C++ (if neccessary)
    I plan it to run on Linux, Mac and Windows and also eventually Android (when QT neccessitas gets more stable).
    There will be a directory called widgets where I will have my widgets .qml file (more files , Button.qml,TextInput.qml...)
    There will be a directory called dialogs,src...
    Now onto my problem. I have not really done much stuff really, this post is just a way to stop bashing qml and qt later when things go wrong and there is a lot of code :D
    Here is the info I need :
    in a .qml source file
    import "src/code.js" as SomeNamespace
    How will that behave on windows where paths are escaped using \ ?
    Then if I have widgets/Button.qml
    how can I import that into my dialogs/SomeDialog.qml
    Will import "widgets/Button.qml" as Button work
    and will it work on windows.
    BTW - How to add new directories in Qt Creator?
    That's all that comes to my mind now.Thanks for helping.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chriadam
      wrote on last edited by
      #2

      Hi,

      Regarding relative imports: we transform paths into platform-canonical form, so doing:
      import "src/code.js" as JS
      should just work on all platforms.

      If you have project/widgets/Button.qml and project/dialogs/SomeDialog.qml you should be able to do:
      import "../widgets"
      inside SomeDialog.qml to gain access to all of the QML document-defined types in the widgets subdir.

      Regarding directories in QtCreator: it is important to note that QtCreator doesn't "see" directories. What it sees are Qt projects and subprojects (which are defined in .pro or .pri files).

      So, if you want a tree of "subdirectory-like" separations in QtCreator, you should use qmake .pro files (or .qmlproject files for pure-qml projects).

      example:

      project/myapplication.pro:

      #start
      TEMPLATE=subdirs
      CONFIG=ordered
      SUBDIRS += widgets dialogs
      #end

      project/widgets/widgets.pro:

      #start
      QT += widgets gui quick qml
      HEADERS += someCppWidget.h
      SOURCES += someCppWidget.cpp
      OTHER_FILES += MyButton.qml
      #end

      project/widgets/dialogs.pro

      #start
      QT += widgets gui quick qml
      HEADERS += someCppDialog.h
      SOURCES += someCppDialog.cpp
      OTHER_FILES += MyDialog.qml
      #end

      etc.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AleksandarJovanov
        wrote on last edited by
        #3

        Thank you for your post.
        It is very informative.
        I have one more question regarding paths.
        When I use c++ what should I use?
        Does qmake fix paths automatically like QML runtime does?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chriadam
          wrote on last edited by
          #4

          qmake will only parse .pro and .pri files, not cpp files.
          For paths in CPP, you can use QUrl::fromLocalFile("some/path") -- and in that case, yes, it should canonicalise the path on the local filesystem, doing slash replacement etc as required.

          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