No headers or source files in QT creator - qt

I'm having a problem with creating new header and source files in QT. I can only add new files to the build, it's grayed for the "main" project as you can see below.
I can create them specifically for the build and they only appear once in the documents area. There is no header tree branch. After I close qt I have to create new ones. I want them to appear in the tree and be connected with the main project. I have "hide source and headers files" option off.
I've obviously tried creating them the way it was shown on the yt. I've searched through settings but didn't found anything I could use.

You will have to add the files manually in CMake.
Go to File>New File and select what type of file you want. Typically it will be a source, header, or both (class).
Edit the CMakeLists.txt file:
qt_add_executable(myapp
myapp.qrc
main.cpp
new_file.cpp
new_file.h
)
Resources like .qml files and things like images (*.png *.jpg) are added in the myapp.qrc file

Related

How do remove a project in qt creator?

When I right click a project, the "Remove project" menu is disabled. Why?
I tried to remove the .pro file which gave me a confusing result.
First I got a message that I could not remove it.
Then I got a dialog asking if I also wanted to remove it from version control.
Finally, I got a messge that the file was gone, clicking it confirmed its non existence, it is still visible in the "projects" treeview however.
You don't remove a project. You close it: File menu->Close Project. You can then delete the file or do whatever you want. I suggest that you acquaint yourself with qmake sufficiently to be able to manually create project files. They are really simple. A project file for a widgets-based project is quite trivial:
QT = widgets
CONFIG += c++11
TEMPLATE = app
SOURCES += main.cpp mywidget.cpp
HEADERS += mywidget.h
go to File>recent projects>clear menu. DONE!

Removing QActions from the ui_mainwindow.h file

My app was started (by someone else) in Qt Designer. For a number of reasons I've decided to put the main form gui together in C++. In the designed I deleted all the gui widgets and removed the menu items from the object tree.
Having got the layout how I want it I started adding in the actions to find that they are still declared in the ui_mainwindow.h file.
Is it safe to manually remove the action declarations from this file? Or is there a way of doing this through Qt designer?
Open your *.ui file in the designer. In the lower right corner you'll see Action Editor. Actions can be deleted from there.

Customise QPushButton with an image

I am using Qt5 and having some problems in setting the back ground image of a QPushButton. I am using Qt Creator and Design to drag and drop the QPushButton. After that I created a source folder and placed an image in that directory and I googled and tried doing
ui->pushButton_play->setStyleSheet(QString::fromUtf8("background-image: url(:/source/play.png);"));
but no success...am I creating the folder in a wrong place?..I created in D:\Qt5_PROJECT_NAME\source or will I make the url(:\\source\\play.png). Nothing is working...please help...
Did you add the images file into .qrc file? A URL start with : has indicated that It will be searched in .qrc file. If .qrc file didn't used, URL should not start with :. Maybe you should access the image file as
ui->pushButton_play->setStyleSheet(QString::fromUtf8("background-image: url(source/play.png);"));
This is The Qt Resource System documentation.

How to specify Code Style settings in a Qt Creator `.pro.shared` file?

I can see from the documentation on https://qt-project.org/doc/qtcreator-2.6/creator-sharing-project-settings.html how to create a .pro.shared file that standardizes Editor settings.
But: is it possible to standardize Qt Creator's "Code Style" settings in a .pro.shared file, and if so, what is the syntax?
There is currently no UI way of doing that, not sure if we will add one at some point.
So you will need to do this manually: Set it up for a user, close the project to make sure the .user file is saved and copy copy the file into a .shared file. Remove everything you do not want to share (keep ProjectExplorer.Project.Updater.FileVersion!), while keeping the XML structure intact. You are a developer, I am sure you will manage:-)
Oh, make sure to use the oldest Qt Creator you want to support (IIRC this was introduced in 2.5, so going older than that won't help) to create the template. Creator will upgrade settings while reading them but it can not downgrade, so .shared files that are too new are going to be ignored.

How can files and classes be renamed in Qt Creator?

How do I rename files and classes (declaration, implementation and uses) in Qt Creator 2.0?
I can't find such feature in there.
There is no such feature in Qt Creator :(
This is what you can do:
To rename files:
close your project
rename files in Windows Explorer or some other tool
open project
update *.pro file, list *.h files in headers, *.CPP files in sources, *.ui files in forms
update all *.ccp files in the #include section to include proper files
To change class names you can use the Ctrl + Shift + R feature that changes class names in header files and source files.
If you also want to rename a form and along with its class, you have to edit your name.ui file and change the widget name and class to the new corresponding value.
You also need to rename some things in your name.h file.
namespace Ui {
class NewValueHere;
}
private:
Ui::NewValueHere* mUI;
In your name.cpp file you also have to adjust the call of creating your mUI.
mUI(new Ui::NewValueHere)
Personnally I needed to do something more.
I renamed my class "Form" to "MainWindow", and I had to go in the directory "build-yourproject...-Debug\ui_mainwindow.h" and replace every "Form" with "MainWindow" (Ctrl+f) and then it worked.
EDIT: This was a manual solution that changes a file that is re-loaded at every build, so this change is automatically lost. The right solution is to go in Qt Creator and in the upper-right corner, under the name "Object", you should have the name of your class, that is what you need to change.

Resources