I'm using QT 5.9.1 working on Mac OS. My project is mobile App with C++ logic and QML UI Layer. All QML files are included into qml.qrc file, so in my .pro file I have
RESOURCES += qml.qrc
Inside qml.qrc there is a list of all resource files I use in Project, such as pictures, icons and QML files, in QT Creator it's displayed OK:
As you can see some QML files are located in ROOT path of qml.qrc when other files are in subfolders , e.g. "qrc:/Elements/".
So problem is that whenether I make changes in Files that located in root of qml.qrc - they are normally recompiled when I press build, rebuild, or clean and build, so I can see my changes. As a result in my build directory I see that qml_qrc.cpp (as I understand this file contains cpp representation of my resource files and is used to compile them) file is refreshed,my changes are applied and everything is OK.
Here is just piece of this file, which begins with cpp hex representation of MainPage.qml resource file.
/****************************************************************************
** Resource object code
**
** Created by: The Resource Compiler for Qt version 5.9.1
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
static const unsigned char qt_resource_data[] = { //
/Users/admin/QtProjects/LazuritApp-temp/MainPage.qml
0x0,0x0,0x7,0xd1, 0x0,
0x0,0x1e,0xbb,0x78,0x9c,0xd5,0x19,0x5d,0x6f,0xdc,0x36,0xf2,0x7d,0x7f,0x5,0x6f,
0xb,0x14,0xbb,0x69,0xa2,0xf5,0xae,0xed,0xa4,0xde,0xa0,0x77,0xf0,0xba,0x49,0x63,
0x20,0x45,0xda,0xda,0x68,0x1e,0xe,0x45,0xc1,0x95,0xa8,0x15,0x2f,0x5a,0x51,0xa5,
0x24,0xdb,0x5b,0xc3,0x40,0xda,0x2,0xed,0x1,0x79,0x28,0x70,0x68,0x71,0xcf,0xf7,
0xf,0xdc,0xbb,0x6b,0x1b,0x34,0x4d,0xfa,0x17,0xb4,0xff,0xa8,0x43,0x52,0x5f,0x94,
..............
But if I change those resource files located in subfolders, qml_qrc.cpp file is not refreshed, so my resource files are not rebuild, even if I try Clean, then rebuild. Even if I do "run qmake" manually and then rebuild. The only thing helps in this situation - to manually delete build folder (or to be more precisely you can just delete qml_qrc.cpp file). So then pressing "Build" will create new qml_qrc.cpp file, which will contain correct code, with changes I've done in my resource files.
Can someone help me or explain why this happens and what can I do in this situation? deleting manually and rebuilding is annoying, but placing all resource files in root path of project is also not a good decision...
I also tried to paste
update qml
qml_scenes.depends = $$PWD/QML Files/OrdersPage.qml
qml_scenes.commands =
QMAKE_EXTRA_TARGETS += qml_scenes
as was described here, but it didn't help
ok, after hours of digging in QTBUGS traces, stackoverflow and others forums I found solution, which somehow satisfies me..
1) Create script file (for me it's .sh file as I working on MAS OS, for Windows it will be .bat file) with "touch" command to qml.qrc file. In my case it contains 2 lines :
#!/bin/sh
Touch qml.qrc
2) Add Custom build step (Projects->Build Settings->Build Steps->Add Custom Process Step). Choose your created .sh file, choose working directory when you build is located. Make this custom step to be the first executed (before qmake and Make)
3)So, now changes in qml resource files will be compiled every time you build the project. Script will firstly touch our qml.qrc file, which will refresh it's modified date, so that qml.qrc (hence, our qml resources too) will be added to makefile dependencies.
it seems to be pretty rough way to solve the problem, but at least you don't have to Clean, Rebuild and so on..
If someone have better solution, please let me know)
Unfortunately, the solution given in a link provided in the comments seems to be incomplete and/or broken. But it can be done like this:
update_qml.target = qml.qrc
update_qml.commands = echo>>$${update_qml.target} # same as touch
update_qml.depends = $$files(path/to/resource/files/*, true) # recurse into subdirs
QMAKE_EXTRA_TARGETS += update_qml
PRE_TARGETDEPS += $${update_qml.target}
For those who interested in how it works, QMAKE_EXTRA_TARGETS produces the following Makefile rule:
qml.qrc: file1 file2 ...
echo>>qml.qrc
So issuing a command make qml.qrc will update the timestamp of qml.qrc as needed. However, to save us from manual typing it every time, we also make use of PRE_TARGETDEPS which fixes the main building rule:
$(DESTDIR_TARGET): qml.qrc $(OBJECTS) and other stuff ...
$(LINKER) flags objects and other stuff ...
So now make utility will scan the previous rule every time while building the target.
Let's say my project is called foo. I created a subdir called subdir in the foo root, using Windows Explorer. I put my main.qml file in subdir. Then I tried to do a project-wide search for "text" in my project. To do this, I pressed Ctrl+Shift+F, selected Project "foo" in Scope, wrote "text" in Search for. No matches were found, though main.qml does contain the string "text". When main.qml is in the project root, the string is found just fine.
Is this a bug in Qt Creator and is it something I can fix in the options?
Qt Creator version: 4.1.0.
Further notes
The .pro file doesn't include main.qml, but the .pro file contains RESOURCES += qml.qrc, and qml.qrc contains <file>subdir/main.qml</file>. The project viewer in Creator does show main.qml in the tree, nested as "Resources -> qml.qrc -> / -> subdir ->main.qml".
If by "project focus" mean it has to be the "Active project" as set by rightclicking a project and selecting "Set 'myproj' as active project", then I have that requirement fulfilled.
I tried including in the project a resource file (called "main2.qml") that resides in the project root, just so I can see if it gets included in the .pro automatically. It did get included, like this:
DISTFILES += \
main2.qml
And, weirdly, now that I included this new file, the old file that resides in a subdir is also searchable.
Even when I removed main2.qml from the project, the files in subdirs remained searchable! They even became searchable in my other project, where I've changed nothing!
Very weird. I expect soon search will start having the problem again, so I'd still like tips on what might have caused the problem.
Make sure the qml file is a part of the project.
A project-scope search only looks in files that are a part of your project. Their on-disk location is not relevant at all. If they don't show up in the project tree, they are not in the probject, period.
Make sure that the File Pattern for the search includes the qml files.
The file pattern elements are comma-delimited (e.g. *.c*, *.h, *.qml). It is a common error to use other delimiters.
sometimes when I rename the path to a qt project, it cannot be run even though I clean qmake and rebuild it!!! the path does not contain any space. and the project is completely correct and I know that the error is for path renaming , for example when I rename :
D:/abd/projects/LAND_2/Land_QT/...
to
D:/abd/projects/LAND_2/Land2_QT_SA/...
it cannot be build and says that some include file is missing(but the file is there!).
what is the problem?
I work with dynamic qt5.2 on windows 7.
Edit:
when I copy the project folder to a new directory( a path upper than current path) then the project can be build and run.
When you rename the path to the project, go to the project folder and delete the file with .pro.user extension. Open the project and Qt will ask you to configure the project. Choose the required kit, build and run the project.It should build successfully now
If you have changed path multiple times the .pro.user file is created multiple times delete all files with this extension and compile
I have an existing QT Creator project. I want to add an entire directory to this project. I see that I can right click in the project file browser tree and "Add Existing Files..." However through this dialog box, I can only add individual files. How can I include an entire directory?
The simplest way is to directly edit your .pro file, add HEADERS += mydir/*.h and SOURCES += mydir/*.cpp and the contents of the whole directory will show up in QT Creator. Further reference: http://qt-project.org/doc/qt-5/qmake-project-files.html
Open a terminal, navigate to the folder where you want to have you project file, and then run the command
qmake -project
This will search the current directory and all subdirectories for files with extensions such as .c, .cpp, .h, etc. (the full list is found by typing man qmake).
But keep in mind that it will overwrite your current .pro file if you already have a project set up.
qmake provides a convenient files function for this very purpose. Adding the following line to your project file will add .cpp files inside the src/ directory:
SOURCES += $$files(src/*.cpp)
By default, this is non-recursive. Setting the second parameter to true recursively finds all files:
SOURCES += $$files(src/*.cpp, true)
The files function was introduced since Qt 5.10.
Nowadays you can just right click on project name and select Add existing directory
My app folder is "app"
It contains both .pro and source files
It has a "bin" folder.
the "DESTDIR = bin\" in my .pro file
however, when building from Qt-Creator, a sibling folder is being created, called "app-build-desktop" and the binaries are stored there under a new "bin" folder.
why is this happening? why is another sibling folder being created and hosts a new bin folder instead of just creating the binary file in my existing "bin" folder.
In the "Projects" area (on the left pane of Qt Creator) there is a "Shadow build" option in the Build Settings. You can uncheck this to disable it.
That being said, it is a useful feature, for example for keeping your actual source directory clean of temporary files that you have to ignore in source control.