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. Confused about directory structure
Forum Updated to NodeBB v4.3 + New Features

Confused about directory structure

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 3 Posters 4.9k Views 2 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.
  • P Offline
    P Offline
    pderocco
    wrote on last edited by
    #1

    Qt 5.12, Qt Creator 4.8.0, Windows 7 32-bit, MSVC 2017 32-bit

    This is my first QML project. I don't recall exactly how I wound up with the directory structure that I have, since I knew exactly nothing when I started. I think I used New File or Project, and created an empty Qt Quick application under 5.11, although now I'm on 5.12.

    The problem is I'm suddenly seeing most of my files in two places in the Qt Creator projects pane. Here's what I've got (described conceptually, because the actual file lists are long, and proprietary).

    My directory tree looks like this:

    MyProject:
        MyProject.pro
        MyProject.pro.user
        qml.qrc
        (*.qml files, including main.qml)
        (*.js files)
        (*.cpp files, including main.cpp)
        (*.h files that go with the .cpp files)
        emu:
            (*.* proprietary data files)
        help:
            (*.html and *.png files used by webengine)
        images:
            (*.png files used by QML)
    

    My project file looks like this:

    QT += qml quick webengine
    
    CONFIG += c++17
    
    SOURCES += \
        (*.cpp files)
    
    HEADERS += \
        (*.h files)
    
    RESOURCES += qml.qrc
    
    qml_scenes.depends = \
        (*.qml and *.js files, each preceded by $$PWD/)
    
    qml_scenes.commands =
    
    QMAKE_EXTRA_TARGETS += qml_scenes
    

    My qml.qrc file looks like this:

    <RCC>
        <qresource prefix="/">
            (*.qml files, wrapped in "file" tags)
            (*.js files, wrapped in "file" tags)
            (emu/*, help/*, and images/*  files, wrapped in "file" tags)
        </qresource>
    </RCC>
    

    The problem is that the tree I see in Qt Creator looks like this:

        MyProject.pro
        Headers:
            (*.h files)
        Sources:
            (*.qml files)
            (*.cpp files)
            qml.qrc
                /
                    emu:
                        (emu/* files)
                    help:
                        (help/* files)
                    images:
                        (images/* files)
                    (*.qml files)
                    (*.js files)
        Resources
            C:\blahblahblah\qml_qmlcache.qrc
                /
                    emu:
                        (emu/* files)
                    help:
                        (help/* files)
                    images:
                        (images/* files)
                    (*.qml files)
                    (*.js files)
    

    Everything seems to compile and run, although I haven't tried deploying anything yet. But this looks Wrong. I don't understand where this arrangement comes from.
    Questions:

    • Why do I see nothing under Resources, except under qml_qmlcache.qrc?
    • Why are my QML files appearing under Sources, along with my .cpp files? They weren't there a while ago. They were just listed under qml.qrc.
    • Where do the "Sources", "Headers", and "Resources" virtual folder names come from?
    • Shouldn't my resources be under Resources?
    • What is qml_qmlcache.qrc, and why should it even be visible to me?
    • Shouldn't my QML files be under Resources, since that's what they are, and not under Sources?
    • When I look at various examples, they look very different from this. Any advice on how my directory structure and project file should really be set up?
    1 Reply Last reply
    0
    • P Offline
      P Offline
      pderocco
      wrote on last edited by
      #7

      It looks like when the Build Settings page adds "CONFIG+=qtquickcompiler", for each xyz.qml file it generates an xyz_qml.cpp that contains a big array of bytes which I assume are byte codes that encode the .qml more efficiently. Since these get compiled as C++, they are considered sources, so Qt Creator implicitly treats the .qml files as sources, too. The result is that the resource system contains these compiled .qml files rather than the original text.

      So I guess this is W.A.D., and the fact that the .qml files appear twice in the Projects tree is just a bit of unfortunate ugliness that doesn't really mean anything.

      But I'm still wondering if there are any better ways to organize my source and resources. Do people sometimes push either their C++ source or their QML source down a level in the directory structure? Does that cause any issues? I don't really like having them in the same folder with the .pro file and the .qrc file.

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #2

        Looks very weird to me. Can you close the project. Remove *.pro.user files. Reload pro file.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        2
        • P Offline
          P Offline
          pderocco
          wrote on last edited by
          #3

          Nuking *.user didn't change anything, but I noticed that it was doing this on the Release build but not the Debug build. The difference is that the Release build configuration's qmake command includes "CONFIG+=qtquickcompiler" but the Debug build doesn't. I guess that redefines *.qml files as "source" files, since they are going to be "compiled" into byte-codes. It's unfortunate that they nonetheless appear in two places in the tree, under Sources, as well as under Sources, then qml.qrc, then /, but that's not a big deal. That long C:\blahblahblah\qml_qmlcache.qrc branch under Resources contains what's left of my resources after the .qml files are removed, since that's what will end up in the resources part of the executable. I guess this is W.A.D.

          1 Reply Last reply
          0
          • KazuoAsanoK Offline
            KazuoAsanoK Offline
            KazuoAsano
            Qt Champions 2018
            wrote on last edited by KazuoAsano
            #4

            Hi @pderocco, Welcome to Qt world!

            I look like something mysterious phenomenon,too.

            I tried creating a project file from your conceptually description.
            Please see the difference with my project view result.
            And, i hope that you look at the my created project file.

            0_1545961570159_sample.png

            You may find something different from your project file.
            Please confirm for my project where pushed at github.

            https://github.com/sazus/QtForum_topic_97918

            P 1 Reply Last reply
            0
            • KazuoAsanoK KazuoAsano

              Hi @pderocco, Welcome to Qt world!

              I look like something mysterious phenomenon,too.

              I tried creating a project file from your conceptually description.
              Please see the difference with my project view result.
              And, i hope that you look at the my created project file.

              0_1545961570159_sample.png

              You may find something different from your project file.
              Please confirm for my project where pushed at github.

              https://github.com/sazus/QtForum_topic_97918

              P Offline
              P Offline
              pderocco
              wrote on last edited by
              #5

              @KazuoAsano Because of your language settings, I can't tell if that's a display of the release or the debug build. When you select the release build, do you not see the .qml files under Sources?

              1 Reply Last reply
              0
              • KazuoAsanoK Offline
                KazuoAsanoK Offline
                KazuoAsano
                Qt Champions 2018
                wrote on last edited by
                #6

                Sorry, The screenshot was debug.
                I try again.
                Oh! wonder, Project view differed between release and debug!

                Debug mode
                0_1545987791162_Screenshot from 2018-12-28 18-01-30.png

                Release mode
                0_1545987836021_Screenshot from 2018-12-28 18-01-52.png

                I don't know much about this....
                I think that These changes have no effect on application, only cosmetic problem....

                The extension qrc file is a resource collection file.
                If you don't use the resource system, you need to deploy qml files and images together with executable files.

                When registered qml/image file in the resource collection file, It's store in the application executable file as a binary file.
                Therefore, you only need to deploy the executable file.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pderocco
                  wrote on last edited by
                  #7

                  It looks like when the Build Settings page adds "CONFIG+=qtquickcompiler", for each xyz.qml file it generates an xyz_qml.cpp that contains a big array of bytes which I assume are byte codes that encode the .qml more efficiently. Since these get compiled as C++, they are considered sources, so Qt Creator implicitly treats the .qml files as sources, too. The result is that the resource system contains these compiled .qml files rather than the original text.

                  So I guess this is W.A.D., and the fact that the .qml files appear twice in the Projects tree is just a bit of unfortunate ugliness that doesn't really mean anything.

                  But I'm still wondering if there are any better ways to organize my source and resources. Do people sometimes push either their C++ source or their QML source down a level in the directory structure? Does that cause any issues? I don't really like having them in the same folder with the .pro file and the .qrc file.

                  1 Reply Last reply
                  0
                  • KazuoAsanoK Offline
                    KazuoAsanoK Offline
                    KazuoAsano
                    Qt Champions 2018
                    wrote on last edited by KazuoAsano
                    #8

                    @pderocco ,
                    I had the same opinion,too. I searched variously knowing your opinion.

                    Certainly, Qt Quick Compiler can generate from "xyz.qml" to "xyz_qml.cpp".
                    However, it had known problems at currentry.

                    The compiler is strictly tied to the Qt version due to its use of internal data structures.
                    At this point we cannot guarantee binary and source compatibilities for these internal data structures and therefore when upgrading to a new Qt version, an update of the compiler is required.
                    It is also necessary to re-compile previously compiled .qml files when upgrading the compiler.

                    Qt Documentation : Qt Quick Compiler Known Issues
                    and
                    Qt Documentation : Qt Quick Compiler

                    If you are using Qt 5.12 and you use Qt 5.13 in the future, you may not be able to use cpp-file generated from qml-file at Qt5.12.

                    but QML Application using memory can be greatly reduced by Qt Quick Compiler.

                    http://blog.qt.io/blog/2018/11/16/qt-quick-performance-improvements-qt-5-12-lts/

                    I believe it will be improved in the future.

                    In reference informations.
                    In my case, It have made a directory structure as below.

                    • /src [Function Code directory] *.cpp/*.h
                    • /ui [UI Code directory] *.ui / *.qml / *.js
                    • /res [Resource directory] *.png / *.icon

                    0_1546011140202_Screenshot from 2018-12-29 00-32-03.png

                    1 Reply Last reply
                    2
                    • P Offline
                      P Offline
                      pderocco
                      wrote on last edited by
                      #9

                      Thanks for the suggestion. I reorganized my project along those lines, and it's easier to navigate around.

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved