Creating Files

You can use wizard templates to add individual files to your projects. The following table lists the wizard templates for creating files.

CategoryWizard TemplatePurpose
C/C++C++ ClassC++ header and source file for a new class that you can add to a C++ project.
C/C++ Source FileC++ source file that you can add to a C++ project.
C/C++ Header FileC++ header file that you can add to a C++ project.
ModelingState ChartState Chart XML (SCXML) file that has boilerplate code for state machines. You can use the classes in the Qt SCXML module to embed state machines created from the files in Qt applications.
ModelUniversal Modeling Language (UML) style model with a structured diagram. However, the model editor uses a variant of UML and has only a subset of properties for specifying the appearance of model elements. For more information, see Modeling.
Scratch ModelScratch model using a temporary file.
QtQt Item ModelSource and header files that you can use to create classes derived from QAbstractItemModel, QAbstractTableModel, or QAbstractListModel.
Qt Designer Form ClassQt Designer form and a matching class for implementing a UI based on Qt widgets.
Qt Designer FormQt Designer form for Qt widget based projects. This is useful if you already have an existing class for the UI logic.
Qt Resource FileResource file for storing binary files in the application executable.
QML File (Qt Quick 2)QML file that imports Qt Quick 2.0 for use in Qt Quick projects.
Qt Quick UI FileUI file (.ui.qml) and the corresponding implementation file (.qml) for use in Qt Quick projects.
JS FileJavaScript file that you can use to write the application logic in Qt Quick projects.
GLSLFragment Shader (OpenGL/ES 2.0)Fragment shader that generates the final pixel colors for triangles, points, and lines rendered with OpenGL. You can use it in both Qt Quick projects and Qt widget based projects.
Vertex Shader (OpenGL/ES 2.0)Vertex shader that transforms the positions, normals, and texture coordinates of triangles, points, and lines rendered with OpenGL. You can use it in both Qt Quick projects and Qt widget based projects.
Fragment Shader (Desktop OpenGL)Fragment shader for use in both Qt Quick projects and Qt widget based projects.
Vertex Shader (Desktop OpenGL)Vertex shader for use in both Qt Quick projects and Qt widget based projects.
GeneralEmpty FileEmpty file that you can save with any filename extension.
Scratch BufferScratch buffer that uses temporary files. You can create this type of files for temporarily storing information that you do not intend to save
JavaJava FileJava class files that you can use to create Java classes.
PythonPython ClassPython class file.
Python FilePython script file using UTF-8 encoding.
Nim (experimental)Nim Script FileEmpty Nim script file using UTF-8 encoding.
Nim FileEmpty Nim source file using UTF-8 encoding.

Creating C++ Classes

The C++ Class Wizard allows you to create a C++ header and source file for a new class that you can add to a C++ project. Specify the class name, base class, and header and source files for the class.

The wizard supports namespaces. To use a namespace, enter a qualified class name in the Class name field. For example: MyNamespace::MySubNamespace::MyClass. The wizard suggests existing namespaces and class names as you type.

"Enter Class Name dialog"

The names of the header and source file are based on the class name. To change the default suffix of a file, select Edit > Preferences > C++ > File Naming.

"C++ File Naming preferences"

In the License template field, you can use predefined wizard variables to specify the path and filename of the license to use in the source and header files.

You can create your own project and class wizards. For more information, see Adding New Custom Wizards.

Creating Resource Files

Qt Creator supports the Qt Resource System, which is a platform-independent mechanism for storing files in the application's executable.

"New File dialog"

The wizard creates a resource collection file (.qrc) that you can manage in the resource editor.

"Editing resource files"

Select Add Files to locate and add individual files.

To list the folders and files in ascending alphabetic order in the source tree, select Sort Alphabetically in the context menu.

By default, resources are accessible in the application under the same file name as they have in the source tree, with a :/ prefix, or by a URL with a qrc scheme. To specify a path prefix for all files in the .qrc file, select Add Prefix and enter the prefix in the Prefix field.

Some resources need to change based on the user's locale, such as translation files or icons. You can specify a locale in the Language field.

Select Remove to remove the selected file from the resource collection. In the Remove File dialog, select the Delete file permanently check box to remove the file from the file system. To remove files that cannot be found in the file system, select Remove Missing Files.

The above functions are also available in the context menu in the Projects view.

Creating OpenGL Fragment and Vertex Shaders

Qt supports integration with OpenGL implementations on all platforms, which allows you to display hardware accelerated 3D graphics alongside a more conventional user interface. For more information, see Qt GUI.

You can use the QOpenGLShader class to compile OpenGL shaders written in the OpenGL Shading Language (GLSL) and in the OpenGL/ES Shading Language (GLSL/ES). QOpenGLShader and QOpenGLShaderProgram shelter you from the details of compiling and linking vertex and fragment shaders.

You can use Qt Creator code editor to write fragment and vertex shaders in GLSL or GLSL/ES. The code editor offers syntax highlighting and code completion for the files.

"New OpenGL file wizard"

© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.