I have a Qt project in Qt Creator. I have a qrc file with the QMLs registered and everything works. However for some reason the "projects" view of Qt Creator doesn't show the QML folder (screenshot attached) like it does for any example project.
I'm just curious. Why does QML folder not show in my project but it shows up for the example projects?
You need to add them to your .pro file (if I'm not wrong it's enough to append them to DISTFILES).
Figures that you have to add the files to the DISTFILES directive.
Related
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.
I am new to Qt. I installed Qt 5 but when i create a new project (Qt widget application) i do not find headers and source files like main.cpp and mainwindow.ui and mainwindow.cpp Although *.pro file is there but nothing else.
mainwindow.cpp does appear on the text editor but there is a message above that
"This file is not the part of any project."
When i checked inside the project directory i can see all the files present but in Qt creator i can not access any of them.
Please help.
The files that Qt Creator generates for you when you create a new project depend on the type of project that you choose to create. F.ex. when you create a new Empty qmake Project, only the .pro file is being created. You can choose a different type of project when creating one, so that Qt Creator will auto generate some more files depending on your needs.
You can add new files to your project by right clicking on the main project folder in Projects menu and choosing either Add New... to create a new file or Add Existing Files... to point Qt Creator to the files that you already have.
This will add a link to the new file in to the .pro file. Lower is the content of the .pro file after adding a couple of new files to the project.
You can also edit the .pro file by hand instead of using the IDE, but Qt Creator (and qmake as well) won't know about the files in your project folder until you add them to the .pro file.
I want to add a background image to a widget and thus I need a resource file but I am not able to create it in Qt Designer. Here is what I did:
From the widget I go to the resources browser and click on the "add new file" button then a new window pops up.
I am asked to point to the .qrc file but this file does not exist and I don't know how to create it.
I googled and found that .qrc files are created using Qt Creator.
Can't I create a .qrc file in Qt Designer ? Do I need to use Qt Creator to create a .qrc file and then use it in QT Designer ?
I am using Qt Designer with PyQt in CentOS 7.0
You only need Qt Designer, and it can be done very easily, like this:
Open the Resource Browser (View -> Resource Browser)
Click the Edit Resources button (first on the left)
Click the New Resource File button (first on the left)
Enter a file name (e.g. resources.qrc) and click Save
Click the Add Prefix button (fourth from the left) and enter a name (e.g. images)
Click the Add Files button (fifth from the left) and add your resources
Using Qt Creator.
(Using the Qt Designer that is inside of Qt creator)
Right clicking on your project
Add new
Step on the left option QT
Qt Resource file
Follow the wizard to add one
I took those instructions from the video QT Resource Files
I would use Qt Creator, since Qt Designer is built in and you can simply create resource files. However, if that's not possible for you, here's a simple qrc data file contents that you can use: -
<RCC>
<qresource prefix="/images">
</qresource>
</RCC>
It creates a prefix called "/images/", ready to add images to the resource. Just create a file with .qrc extension and add that.
I've added a QAction to my QToolBar in my MainWindow in Qt Designer (using the Qt Creator IDE) and given that Action an icon (done by "Choose File" and selecting my .png located in the same directory as my project and source code). The icon shows up fine in the toolbar in Qt Designer, but does not show when the project is running. I've had similar trouble when choosing the title bar icon on windows. I've never used graphics in Qt before, is there something special I need to do?
Screenshot:
I found myself doing all the right stuff, adding a qrc file and placing my icons there. When I run the program no deal.
Turn out I was forgetting to run qmake:
Right click your project's name and select "Run qmake". Or go to Build>Run qmake.
Everytime you change something in the .pro file you need to run qmake again. Creating a resource file implicitly adds argunments to the .pro file, so you need to do it.
Hope it helps other people out there.
Did you make a QRC file (that is, Qt's equivalent of a resource file?)
If not, that would explain what you're seeing. The icons will show up in the creator, but not in the final compiled executable. Have a look at this:
http://doc.qt.io/qt-5/resources.html
Also in case of shadow build don't forget to use windeployqt.exe on your application executable file. After that several folders will be added to your build directory. Particulary two important folders: iconengines and imageformats which contain several dlls needed to load and draw the icon.
Have you tried opening up the Project file. For example, my project file is named menu.pro and it contains the following:
TEMPLATE = app
QT = gui core
CONFIG += qt debug warn_on console
DESTDIR = bin
OBJECTS_DIR = build
MOC_DIR = build
UI_DIR = build
FORMS = ui/mainwindow.ui
HEADERS = src/mainwindowimpl.h
SOURCES = src/mainwindowimpl.cpp src/main.cpp
RESOURCES = Images.qrc
The last line (RESOURCES = Images.qrc) is what you need to put in your project file: of course, use the name that you used for your resources file, in my case, it is Images.qrc.
While adding icons use "Choose Resource" option instead of "Choose
File" option.
Right click your project's name and click "Run
qmake".
Also make sure you don't forget to include the qrc file in the code (e.g. in main(...)) with Q_INIT_RESOURCE(MyIconResource);
This can also lead to missing icons in the final exe.
I also faced such a problem. In my case, I closed qt creator and deleted the build folder (something like build-projectname.. ). Then restarted qt creator. Then magically my icon showed up on running application.
I often use this trick when qt doesn't behave well.
I'm using Qt Creator.
I'm using the signals and slots editor, and I want to see the code it generates.
How can I see the code?
Thanks!
Let's say you have in Qt Creator a form file called widget.ui.
Once you've compiled your project, you'll find in your project folder a filed called ui_widget.h.
If you open it, you'll see the code generated by the uic tool.
when you use qt creater, this one is going to create a file with the name of your project, in my case it is called "build-prueba-Desktop_Qt_5_7_0_GCC_64bit-Debug", then in that file you have to look for a file with the "ui_" prefix, into that, you have the code you need