How to properly add a .qrc file to a QT 6 widget app with Cmake as building system? - qt

I'm trying to use a .qrc file to store icon images for my QT application but the Resources.qrc file never appears in resource selection. I'm using CMake as building system and 6.3.1 QT version.
When simply adding Resource.qrc to source files with AUTORCC ON file never appears in project tree, when specifically written as project source in CMakeLists it appears in project tree, but never in resource selection when I'm trying to set ToolButton icon, no matter if I add prefix and images or not.
When AUTORCC is OFF and qt_add_resources(PROJECT_SOURCES Resources.qrc) added to CMakeLists, Resources.qrc file appears in CMake modules folder in a tree, but again, never in resource selection.
There are a lot of guides about .qrc when QMake is building system, but I hardly found anything about same thing with CMake, and none of them helped me, maybe I couldn't understand them properly. Sorry for possible mistakes, I'm new in programming and english isn't my native language. I'll be grateful for any help.

Related

Autocomplete in Qt Creator: how to add header files for a cmake project

If I am making a Qt Creater project using cmake, rather than qmake, how can I tell Qt Creator where to look for header files for autocompletion? In CMakeLists.txt, I can specify where to look for heading in compilation, but Qt Creator will not read this until I build the project.
You can make headers show up in CMake by including them in the sources list for a target you're building, alongside the source files. This works for files that are part of your project.
For header files somewhere on your system where the compiler can find them, I'd guess that running CMake (to generate the Makefile) should be enough for Qt Creator to find them.

QT creator Build fails unless administrator

I have a QT project in QT creator. I have been getting strange behavior from it. Unless I open QT Creator with administrative permissions, it won't build at all complaining that it can't start process qmake (qmake is in the right place). My shadow build specifies ..\bin folder as the build. My complete structure is:
project
|
+--- bin
+--- src
So they are at the same level. What could be the issue here?
The problem is that when I use administrator rights, the project builds in C:\Users\bin which isn't right right place.
The actual error given is:
Could not start process "c:\qtsdk\desktop\qt\4.8.1\mingw\bin\qmake.exe"
It sounds like a number of your paths or locations may be off. They could be in the Qt Projects Configure dialog or it could be in your .pro file.
Does a simple "Hello World" example build, without editing the defaults for the folder structures? Do the examples of the Qt SDK build?
Did you install Qt at the root of the C drive? Nesting it in your documents or somewhere else can put a space in the Qt Path variable, which I don't think is supported well by Qt Creator and QMake without a lot of work.
Hope that helps.

Using Qt Creator in QML Design mode, how to reference an image using qrc path?

So, we have an embedded Linux system running Qt and we compile all of our icons (.png format) into our executable using the resource file. The problem is that I want to be able to use the Qt Creator QML Designer to visually see our screens as we are laying them out, but it only allows me to select a relative file system path (i.e. not a path to the resource). If I go to edit mode and put the qrc:/image.png it works in run time but the image doesn't show up in the QML Design mode. Has anyone ever done this or know if it is possible?
There is at least a workaround:
Put everything in the resource file (the qml files and the icons), and when you'll edit the file in Qt Quick Designer, all paths will be relative so the icons will be visible.
Everything is described there: Managing resource files with the Qt resource system
And to avoid deploying the qml files, you'll have to remove/comment the following line from your .pro:
DEPLOYMENTFOLDERS = folder_01
and replace it with:
OTHER_FILES = <list of qml files>

Qt designer does not update the gui

Someone wrote out a GUI in Qt designer earlier and now I have to modify some small parts (i.e. add a button/functionality).
Premise:
I add the new feature/make any modification to the .ui file in Designer.
I can go to edit mode and see that this makes changes to the xml format of the .ui file
Problem:
When I build and run Qt, the old version of the .ui is what is shown (without my feature upgrades).
I tried cleaning everything and running qmake, but to no avail.
Any ideas for why this could be happening?
I had the same problem and it was solved when I disabled "Shadow Build" in "Projects" mode.
UPD:
Still receiving upvotes for this answer makes me sad for 2 reasons
it is trivial
the issue is still there after almost 5 years
I could solve this problem wihtout change Shadow Build configuration.
In my project I want to build with output files into build-ProjectName-Debug
But the QtCreator is not smart to check if are not files moc_FileName.cpp and ui_FileName.h into build directory.
This problem occur because if these files moc_FileName.cpp and ui_FileName.h are into project directory the QtCreator uses them and does not recognize any modification on .ui files.
The solution to this problem was easy to me:
Remove all moc_FileName.cpp and ui_FileName.h from project directory and Rebuild.
These files will be created into build-ProjectName-Debug and all modifications will be there.
When you change a .ui file, someone needs to run uic.exe on the file to generate a header file. For example, for a window called MyWindow.ui, this will generate a file called ui_MyWindow.h.
This is then what is used when the application is rebuilt.
You don't specify how you are building or on what OS, so it is hard to help you on that end. If you are using Visual Studios it is possible to integrate your .ui files into your projects so that when you change any .ui file, all the generated files will be recreated automatically. The same is possible if you are using .pri files.
In any case, I would run:
uic.exe -o ui_yourfile.h yourfile.ui
Please change the names of the files to the ones you are using.
uic.exe can be found in your Qt bin directory.
Then once you have the generated header file, try to find where it goes in the build directory. Then rebuild.
This is what helped me personally, add to qmake file:
UI_DIR = $$PWD
I solve this problem by cleanthenbuild.I find that ,if I checked Shadow Build,qtCreator will use the old .obj,other than generate new .obj even if the ui_xxx.h had been changed,to generate .exe when debug agin.My enviroment is qt5.5 + msvc2013.
I had the same problem and was able to solve it by deleting all the Makefiles in the build directory, then rebuilding from scratch. For some reason, these files are not deleted when you run Clean Project from Qt Creator.
Same problem for me.
Nothing works until I changed the installation from Qt 5.0.2 (MSVC 2010) to Qt 5.0.2 (mingw).
Now it is working again...wired
I experienced the same problem: no ui changes appeared after building.
The problem as mentioned above is that the ui files are not getting remade.
Unchecking shadow build solved the problem for me but only once. After that I could not see subsequent ui changes again. So I rechecked shadow build and deleted the existing shadow build folder. This works consistently now, as long as I delete all the build files. But that's lame. It should be able to detect ui changes and remake the files.
I think this should be logged as a bug in Qt Creator/Designer.
I deleted all auto gen file in source folder. when I unchecked shadow build, auto gen file was created in source folder. after when I checked shadow build, compiler only use source folder's gen file. So I deleted all auto gen file(ui_, moc_) and then ui was updated always.
In my case, the problem was caused by a rename of the .ui file. Qt Creator didn't update the #include for the header file "ui_[name_of_ui_file].h" in the .cpp file corresponding to the form. Anyway, cleaning up all the "ui_*.h" files in the shadow build folder solved the issue (I guess unchecking "shadow build" in the Project tab would produce the same effect).
Have you been playing with the system date or time or they were different from those of your fellow's computer? I was changing the time to some hours later for testing purposes (and compiling the project in the meantime) and after restoring it to current time, the compiled files were not updated because they were newer than the compilation time. Running Clean did not delete those files. Unchecking the Shadow build option only gave me crashes and an untraceable 0xc0000135 error. Deleting manually the moc_*.o and *.cpp files with future date/time from the building directory and compiling the whole project again was the solution for me.
Add the following line into .pro file
UI_DIR = $$PWD
As mentioned above, the ui files are not getting recreated. For me, the easiest solution is just hitting Rebuild instead of Build. No need to go into project submenues each time.
As long as your project is not too big, this is OK (apart from this is an anoying bug that qt has for long years now)
I had the same problem and then realized that I have modified the .pro file manually: that is I made "illegal" thing - moved mainwindow.ui under DISTFILES (by default all ui files are grouped under FORMS).
Returned back to FORMS and now everything works fine
This happened to me when I deleted elements from my form in the designer, but still had those elements referenced in the .cpp file. After I deleted those references in .cpp I was able to rebuild and the compiler stopped complaining.

How can I create a new Qt localisation for Qt itself?

Our application is localised and I have pulled in all the standard Qt_*.qm files as well so that my Qt dialogs are translated as much as possible.
However one of our distributors wants to add the Danish translation and its not in the standard Qt translation files.
How can I get Qt to create the file so I can send it off for translation?
There is some information about translation of Qt itself:
http://doc.trolltech.com/4.6/internationalization.html#produce-translations
it's said that templates for qt translation (*.ts files) should be in the ${QTDIR}/translations directory. I can't see them in my Qt4 installation from official Ubuntu repository but I think they should be included in distributions provided by Nokia on official download page.
Edit
Idea how to generate new empty *.ts file for qt itself can be found in translations/translations.pri directory of qt sources. For Qt 4.6.3 it will be
lupdate -locations relative -no-ui-lines -I../include -I../include/Qt corelib gui-ts ../qt_my.ts

Resources