creator-projects-creating.qdoc 17.6 KB
Newer Older
1 2
/****************************************************************************
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5
**
6
** This file is part of the Qt Creator documentation.
7
**
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16
** GNU Free Documentation License Usage
17 18
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
19 20 21 22
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
23 24 25 26 27 28 29 30 31 32
**
****************************************************************************/

// **********************************************************************
// NOTE: the sections are not ordered by their logical order to avoid
// reshuffling the file each time the index order changes (i.e., often).
// Run the fixnavi.pl script to adjust the links to the index order.
// **********************************************************************

/*!
33
    \contentspage {Qt Creator Manual}
34 35 36 37 38 39
    \previouspage creator-project-managing.html
    \page creator-project-creating.html
    \nextpage creator-project-opening.html

    \title Creating Projects

40 41 42 43
    Creating a project enables you to:

    \list

44
        \li Group files together
45

46
        \li Add custom build steps
47

48
        \li Include forms and resource files
49

50
        \li Specify settings for running applications
51 52 53 54 55 56 57 58 59

    \endlist

    Setting up a new project in \QC is aided by a wizard that guides you
    step-by-step through the project creation process. The wizards prompt you
    to enter the settings needed for that particular type of project and create
    the necessary files for you. You can add your own custom wizards to
    standardize the way subprojects and classes are added to a project.

60
    Most wizards create projects that use the Qt build tool, qmake. It is a
61 62 63 64
    cross-platform system for build automation that helps simplify the build
    process for development projects across different platforms. qmake
    automates the generation of build configurations so that only a few lines
    of information are needed to create each configuration. For more
65
    information about qmake, see the \l{qmake Manual}.
66
    You can modify the build and run settings for qmake projects in the
67
    \uicontrol Projects mode.
68

69 70
    You can use wizards also to create plain C or C++ projects that use
    qmake, Qbs, or CMake, but do not use the Qt library.
71 72

    In addition, you can import projects as \e {generic projects} that do not
73 74
    use qmake, Qbs, or CMake. This enables you to use \QC as a code editor and
    to fully control the steps and commands used to build the project.
75

76 77
    You can install tools for mobile devices as part of Qt distributions.
    The \l{glossary-buildandrun-kit}{kits} and build and run settings for the
78
    installed device types are set up automatically. However, you might need to
79 80 81 82 83
    install and configure some additional software on the devices to be able to
    connect to them from the development PC.

    \section1 Using Project Wizards

84 85
    In the first step, you select a template for the project. You can filter
    templates (1) to view only those that apply to a particular target platform.
86 87 88

    \image qtcreator-new-qt-quick-project-wizard.png

89 90
    Next, you select a location for the project and specify settings for it.

91 92 93
    When you have completed the steps, \QC automatically generates the project
    with required headers, source files, user interface descriptions and project
    files, as defined by the wizard.
94

95 96 97 98
    For example, if you choose to create a Qt Quick application, \QC generates a
    QML file that you can modify with the integrated \QMLD.

    \section1 Selecting Project Type
99 100 101 102 103

    You can use wizards to create following types of projects:

    \list

104
        \li Applications
105 106 107

        \list

108
            \li Qt Widgets Application
109 110 111 112

                Use \QD forms to design a Qt widget based user interface for the
                desktop and C++ to implement the application logic

113
            \li Qt Quick Application
114

115
                Create a Qt Quick application that contains both QML and C++
116
                code. The project includes a QQuickView.
117 118
                You can build the application and deploy it to desktop,
                embedded, and mobile target platforms.
119

120
            \li Qt Quick Controls Application
121

122
                Create a Qt Quick application using
123
                \l{http://doc.qt.io/qt-5/qtquickcontrols2-index.html}
124
                {Qt Quick Controls 2} (requires Qt 5.7 or later),
125
                \l{http://doc.qt.io/qt-5/qtquickcontrols-index.html}
126
                {Qt Quick Controls}, or
127
                \l{http://doc.qt.io/qt-5/qtlabscontrols-index.html}
128
                {Qt Labs Controls} (only for Qt 5.6)
129

130 131 132 133 134 135
            \li Qt Canvas 3D Application

                Create a Qt Quick application that imports the Qt Canvas 3D
                module and, optionally, includes \l{http://threejs.org}
                {three.js}.

136
            \li Qt Console Application
137

138
                Use a single main.cpp file
139 140 141

        \endlist

142
        \li Libraries
143 144 145

        \list

146
            \li C++ Library
147

148
                Shared or static C++ library based on qmake
149

150
            \li Qt Quick 1 Extension Plugin
151

152 153
                C++ plugin that makes it possible to offer extensions that can
                be loaded dynamically into Qt Quick 1 applications by using the
154 155
                QDeclarativeEngine class

156
            \li Qt Quick 2 Extension Plugin
157 158 159 160 161

                C++ plugin that makes it possible to offer extensions that can
                be loaded dynamically into Qt Quick 2 applications by using the
                QQmlEngine class

162
            \li \QC Plugin
163

164 165 166

        \endlist

167
        \li Other Projects
168 169 170

        \list

171
            \li Qt Unit Test
172 173

                Qt unit tests for features or classes
174

175
            \li Qt Auto Test
176

177 178
                Projects with boilerplate code for a Qt test. For more
                information, see \l {Creating Qt Tests}.
179

180 181 182 183 184 185 186 187 188 189
            \li Qt Quick UI

                Use a single QML file that contains the main view. You can
                review Qt Quick UI projects in a \l{Previewing QML Files}
                {preview tool} and you need not build them.

            \li Qt Quick Controls UI

                Like a Qt Quick UI project, but using Qt Quick Controls

190
            \li Qt Custom Designer Widgets
191 192

                Custom \QD widget or widget collection
193

194
            \li Empty Qt Project
195 196

                Empty Qt project that is based on qmake but does not use any
197 198
                default classes

199
            \li Subdirs Project
200 201 202

                Subprojects that enable you to structure your qmake projects as
                a tree hierarchy
203

204 205 206 207 208 209
            \li Code Snippet

                Creates a qmake project from a code snippet. When fixing bug
                reports that contain a code snippet, you can place the code
                snippet into a project to compile and check it.

210 211
        \endlist

212
        \li Non-Qt Projects
213

214 215
        \list

216
            \li Plain C or C++ Application
217

218
                Plain C or C++ application that uses qmake, Qbs, or CMake but does
219
                not use the Qt library
220

221 222 223 224 225 226 227 228 229 230 231
            \li Nim Application (experimental)

                \l{http://nim-lang.org/}{Nim} application that uses qmake
                or CMake but does not use the Qt library

                \note The \uicontrol {Nim Application} option becomes visible
                after you enable the experimental Nim plugin. Select
                \uicontrol Help > \uicontrol {About Plugins} >
                \uicontrol {Other Languages} > \uicontrol Nim, and then restart
                \QC.

232
        \endlist
233

234
        \li Import Project
235 236 237

        \list

238
        \li Project from version control
239 240 241

            Import a project from a supported version control system. For more
            information on how version control systems are integrated in
242 243
            \QC, see \l{Using Version Control Systems}

244 245 246 247 248 249 250 251 252
        \li Import as qmake Project

            Import an existing project that does not use any of the supported
            build systems: qmake, Qbs, CMake, or Autotools. The wizard creates
            a qmake .pro file, which enables you to use \QC as a code editor and
            as a launcher for debugging and analysis tools. However, if you want
            to build the project, you might need to edit the generated .pro
            file.

253
        \li Import Existing Project
254 255

            Import an existing project that does not use any of the supported
256 257
            build systems: qmake, Qbs, CMake, or Autotools. This enables you to
            use \QC as a code editor
258 259

        \endlist
260 261 262

    \endlist

263
    To create a new project, select \uicontrol File > \uicontrol{New File or Project} and
264
    select the type of your project. The contents of the wizard dialogs depend
265
    on the project type and the \l{glossary-buildandrun-kit}{kits} that you select in the
266
    \uicontrol {Kit Selection} dialog. Follow the instructions of the wizard.
267 268

    For examples of creating different types of projects, see
269
    \l{Tutorials}.
270 271 272 273 274

    For more information about creating Qt Quick projects, see
    \l {Creating Qt Quick Projects}.

    To change the location of the project directory, and to specify settings
275 276
    for building and running projects, select \uicontrol{Tools} > \uicontrol{Options} >
    \uicontrol{Build & Run} > \uicontrol{General}.
277

278
    To specify build and run settings for different target platforms,
279
    select \uicontrol Projects.
280 281 282 283 284 285 286 287

    \section1 Adding Files to Projects

    You can use wizards also to add individual files to your projects.
    You can create the following types of files:

    \list

288
        \li C++
289

290 291 292
            C++ class, source, or header files that you can use to write the
            application logic in both Qt Quick projects and
            Qt widget based projects
293

294
        \li Qt
295

296
        \list
297

298
            \li \QD forms and \QD form classes, which specify parts of user
299
                interfaces in Qt widget based projects
300

301
        \li Qt resource files, which allow you to store binary files in the
302 303
            application executable

304
        \li QML files, which specify items in Qt Quick projects.
305 306 307 308
            \uicontrol {Qt Quick 1} creates a QML file that imports Qt Quick 1.1 and
            \uicontrol {Qt Quick 2} creates a QML file that imports Qt Quick 2.0.
            Select \uicontrol {Qt Quick 1} to add files to a Qt Quick 1 application
            and \uicontrol {Qt Quick 2} to add files to a Qt Quick 2 application.
309 310
            \uicontrol {Qt Quick UI File} creates an UI form (\e .ui.qml) and
            the corresponding QML file.
311

312
        \li JavaScript files that you can use to write the application logic in
313 314
            Qt Quick projects

315 316
        \endlist

317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
        \li Models and state charts

        \list

            \li Universal Modeling Language (UML) style models with structured
                diagrams. However, the model editor uses a variant of UML and
                provides only a subset of properties for specifying the
                appearance of model elements. For more information, see
                \l {Modeling}.

            \li State Chart XML (SCXML) files that contain boilerplate code for
                state machines. You can use the classes in the \l {Qt SCXML}
                module to embed state machines created from the files in Qt
                applications.

        \endlist

334
        \li GLSL
335 336 337 338

            GLSL files that define fragment and vertex shaders in both Qt Quick
            projects and Qt widget based projects

339
        \li General
340

341 342
        \list

343
            \li Text files
344

345
            \li Scratch buffers that use temporary files. You can create this
346 347 348 349
                type of files for temporarily storing information that you do
                not intend to save

        \endlist
350

351 352 353 354
        \li Java

            Java class files that you can use to create Java classes.

355 356 357 358 359
        \li Python

            Python class and source files that you can use to create Python
            classes and scripts with UTF-8 encoding.

360 361 362 363
        \li Nim (experimental)

            Nim source files with UTF-8 encoding.

364 365 366 367
    \endlist

    \section2 Creating C++ Classes

368
    The \uicontrol {C++ Class Wizard} allows you to create a C++ header and source
369 370 371
    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.

372
    The wizard supports namespaces. To use a namespace, enter a qualified
373
    class name in the \uicontrol {Class name} field. For example:
374 375 376 377 378
    MyNamespace::MySubNamespace::MyClass.

    \image qtcreator-cpp-class-wizard.png "Enter Class Name dialog"

    The names of the header and source file are based on the class name. To
379 380
    change the default suffix of a file, select \uicontrol Tools > \uicontrol Options >
    \uicontrol {C++} > \uicontrol {File Naming}.
381

382 383 384 385 386 387
    \image qtcreator-options-cpp-files.png "File Naming tab in Options"

    In the \uicontrol {License template} field, you can use
    \l{Using Variables in Wizards}{predefined wizard variables} to specify the
    path and filename of the license to use in the source and header files.

388 389 390 391 392 393 394 395
    You can create your own project and class wizards. For more information,
    see \l{Adding New Custom Wizards}.

    \section2 Creating OpenGL Fragment and Vertex Shaders

    Qt provides support for 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
396
    \l{Qt GUI}.
397

398
    You can use the QOpenGLShader class to compile OpenGL shaders written in the
399
    OpenGL Shading Language (GLSL) and in the OpenGL/ES Shading Language
400 401
    (GLSL/ES). QOpenGLShader and QOpenGLShaderProgram shelter you from the
    details of
402 403 404 405 406 407 408 409 410 411 412
    compiling and linking vertex and fragment shaders.

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

    \image qtcreator-new-opengl-file.png "New OpenGL file wizard"

    \section2 Displaying Additional File Types in Projects Pane

    \QC determines whether to display files from the project folder
413
    in the \uicontrol Projects pane depending on the file type (.pro, .pri, .cpp,
414
    .h, .qrc, and so on). To display other types of files, edit the
415
    project file. Add filenames as values of the \c {DISTFILES} variable.
416 417 418
    You can also use wildcards.

    For example, the following code specifies that text files are displayed
419
    in the \uicontrol Projects pane:
420 421 422

    \code

423
    DISTFILES += *.txt
424 425 426

    \endcode

427
    This also makes the files available in the \uicontrol Locator.
428 429 430

    \section1 Adding Subprojects to Projects

431 432 433 434 435 436 437 438
    In addition to Qt libraries, you can link your application to other
    libraries, such as system libraries or your own libraries. Further, your
    own libraries might link to other libraries. To be able to compile your
    project, you must add the libraries to your project. This also enables
    code completion and syntax highlighting for the libraries.
    The procedure of adding a library to a project depends on the build
    system that you use.

439
    When you create a new project, you can add it to another project as a
440
    subproject in the \uicontrol{Project Management} dialog. However, the root project
441 442
    must specify that qmake uses the \c subdirs template to build the project.

443
    To create a root project, select \uicontrol {File > New File or Project >
444 445
    Other Project > Subdirs Project > Choose}.

446
    On the \uicontrol Summary page, select \uicontrol {Finish & Add Subproject} to create
447 448 449
    the root project and to add another project, such as a C++ library.

    The wizard creates a project file (.pro) that defines a \c subdirs template
450
    and the subproject that you add as a value of the \l{Variables#subdirs}
451 452
    {SUBDIRS variable}. It also adds all the necessary files for the subproject.

453 454
    To add more subprojects, right-click the project name in the \uicontrol Projects
    pane, and select \uicontrol {New Subproject} in the context menu.
455

456 457
    To remove subprojects, right-click the project name in the \uicontrol Projects
    pane, and select \uicontrol {Remove Subproject} in the context menu.
458

459
    To specify dependencies, use the \uicontrol{Add Library} wizard. For more
460
    information, see \l{Adding Libraries to Projects}.
461

462 463 464 465 466 467
    \section1 Binding Keyboard Shortcuts to Wizards

    If you use a wizard regularly, you can bind a custom keyboard shortcut to
    it. Triggering this keyboard shortcut will directly open the wizard without
    the need to navigate to \uicontrol File > \uicontrol {New File or Project}.

Leena Miettinen's avatar
Leena Miettinen committed
468 469
    Keyboard shortcuts for wizards can be set in \uicontrol Tools >
    \uicontrol Options > \uicontrol Environment > \uicontrol Keyboard >
470 471
    \uicontrol Wizard. All wizard actions start with \uicontrol Impl there.

472 473 474
    \section1 Related Topics

    \list
475 476 477
        \li  \l{Opening Projects}
        \li  \l{Adding Libraries to Projects}
        \li  \l{Adding New Custom Wizards}
478
        \li  \l{Using Other Build Systems}
479 480
    \endlist

481
*/