qtcreator.qdoc 136 KB
Newer Older
1 2 3 4 5 6
// **********************************************************************
// 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.
// **********************************************************************

7

con's avatar
con committed
8 9 10
/*!
    \contentspage{index.html}{Qt Creator}
    \page index.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
11
    \nextpage creator-overview.html
con's avatar
con committed
12 13 14

    \title Qt Creator Manual

con's avatar
con committed
15
    \section1 Version 1.3.80
con's avatar
con committed
16

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
17 18 19 20 21
    Qt Creator provides a cross-platform, complete integrated development
    environment (IDE) for developing Qt projects. It is available for Linux,
    Mac OS X and Windows operating systems. You can use Qt Creator to develop
    applications for desktop and Symbian platforms. For more information, see
    \l{Operating systems and supported platforms}.
con's avatar
con committed
22

23
    \note Please report bugs and suggestions to the
con's avatar
con committed
24
    \l{http://bugreports.qt.nokia.com}{Qt Bug Tracker}.
25 26 27
    You can also join the Qt Creator mailing list. To subscribe,
    send a message with the word \e subscribe to
    \l{mailto:qt-creator-request@trolltech.com}
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
28
    {qt-creator-request@trolltech.com}. For more information about Qt mailing
29
    lists, visit \l{http://lists.trolltech.com}{http://lists.trolltech.com}.
con's avatar
con committed
30

31 32
    \raw HTML
    <img border="0" style="float:right;" src="images/qtcreator-screenshots.png" />
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
33
    \endraw
34

con's avatar
con committed
35
    \list
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
       \o \l{Operating Systems and Supported Platforms}
       \o \l{Quick Tour}
       \o \l{Writing a Simple Program}
       \o \l{Using the Editor}
            \list
                \o \l{Finding and Replacing}
                \o \l{Refactoring}
                \o \l{Searching With the Locator}
            \endlist
       \o \l{Managing Projects}
            \list
                \o \l{Creating a Project}
                \o \l{Setting Up a qmake Project}
                \o \l{Setting Up a CMake Project}
                \o \l{Setting Up a Generic Project}
                \o \l{Managing Sessions}
            \endlist
       \o \l{Developing Applications}
            \list
                \o \l{Developing Maemo Applications}
                \o \l{Developing Symbian Applications}
            \endlist
       \o \l{Debugging}
       \o \l{Using Version Control Systems}
       \o \l{Tips and Tricks}
       \o \l{Keyboard Shortcuts}
       \o \l{Known Issues}
       \o \l{Glossary}
       \o \l{Acknowledgements}
con's avatar
con committed
65 66 67
    \endlist
*/

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
68

con's avatar
con committed
69 70
/*!
    \contentspage index.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
71
    \previouspage index.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
    \page creator-os-supported-platforms.html
    \nextpage creator-quick-tour.html

    \title Operating Systems and Supported Platforms

    \section1 Operating Systems

    Qt Creator is available in binary packages for the following operating
    systems:
    \list
        \o Windows XP Service Pack 2
        \o Windows Vista
        \o (K)Ubuntu Linux 7.04 32-bit and 64-bit with the following:
           \list
               \o g++
               \o make
               \o libglib2.0-dev
               \o libSM-dev
               \o libxrender-dev
               \o libfontconfig1-dev
               \o libxext-dev
               \o libfreetype6-dev
               \o libx11-dev
               \o libxcursor-dev
               \o libxfixes-dev
               \o libxft-dev
               \o libxi-dev
               \o libxrandr-dev
               \o If you are using QtOpenGL, libglui-dev
           \endlist
        \o Mac OS 10.4 or later with the following:
           \list
               \o Xcode tools for your Mac OS X version available from your Mac
                  OS X installation DVDs or at \l http://developer.apple.com.
           \endlist
    \endlist

    \section1 Building Qt Creator

    To build Qt Creator itself from the source, you need:
    \list
        \o Qt 4.6.0 or later
        \o On Windows, MinGW 4.4 or Microsoft Visual Studio 2008
    \endlist

    \section1 Supported Platforms

    \table
        \header
            \o {1,2} Operating system
            \o {2,1} Platform
        \header
            \o Desktop
            \o Symbian
        \row
            \o Windows
            \o Yes
            \o Yes
        \row
            \o Linux
            \o Yes
            \o No
        \row
            \o Mac OS X
            \o Yes
            \o No
    \endtable
*/


/*!
    \contentspage index.html
    \previouspage creator-os-supported-platforms.html
con's avatar
con committed
145
    \page creator-quick-tour.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
146
    \nextpage creator-writing-program.html
con's avatar
con committed
147

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
148
    \title Quick Tour
con's avatar
con committed
149

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
150 151
    The figure below shows some of the components of Qt Creator in
    \gui{Edit mode}.
con's avatar
con committed
152 153 154

    \image qtcreator-breakdown.png

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
155
    \section1 Qt Creator Modes
con's avatar
con committed
156

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
157 158 159 160
    The mode selector allows you to quickly switch between tasks such as
    editing project and source files, configuring how projects are built and
    executed, and debugging your applications. To change modes, click the
    icons, or use the \l{keyboard-shortcuts}{corresponding keyboard shortcut}.
con's avatar
con committed
161 162

    \list
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
        \o Use the \gui Welcome mode to open recent sessions and projects.
        \o Use the \gui Edit mode to edit project and source files.
           \l{The sidebar} in the Edit mode provides different views for
           browsing files.
        \o Use the \gui Debug mode to inspect the state of your program while
           debugging. For more information, see \l Debugging.
        \o Use the \gui Projects mode to configure project builing and
           execution. For more information, see \l{Managing Projects}.
        \o Use the \gui Help mode to view Qt documentation. For more
           information, see \l{Qt Help Integration}.
        \o Use the \gui Output mode to examine, for example, build issues
           and compile and application output. This information is also
           available in \l{The output panes}{the output panes}.
    \endlist

    Certain actions in Qt Creator trigger a mode change. For example,
    \gui Debug > \gui{Start debugging} > \gui{Start debugging}
    automatically switches to \gui Debug mode.


    \section1 The Sidebar
con's avatar
con committed
184

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
185 186
    Use the sidebar to browse files, projects and bookmarks.
    \image qtcreator-sidebar.png
con's avatar
con committed
187

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
188 189 190 191 192 193 194 195 196
    You can select the content of the sidebar in the sidebar menu:
    \list
        \o \gui Projects shows a list of projects open in the current
           session.
        \o \gui{File System} shows the content of the currently selected
           directory.
        \o \gui Bookmarks shows all bookmarks for the current session.
        \o \gui{Open Documents} shows currently open files.
    \endlist
con's avatar
con committed
197

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
198 199 200 201 202 203 204 205 206 207 208
    You can change the view of the sidebar in the following ways:
    \list
        \o To toggle the sidebar, click \inlineimage qtcreator-togglebutton.png
           or press \key Alt+0 (\key Cmd+0 on Mac OS X).
        \o To split the sidebar, click \inlineimage qtcreator-splitbar.png
           . When you split the sidebar, the new view shows the same
           contents as the view you are splitting.
        \o To close a sidebar view, click
           \inlineimage qtcreator-closesidebar.png
           .
    \endlist
con's avatar
con committed
209 210


Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
211
    \section2 Project Tree
con's avatar
con committed
212

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
213 214 215
    When the sidebar shows projects, they are displayed in a project tree. The
    project tree contains a list of all projects open in the current session.
    The files for each project are grouped according to their file type.
con's avatar
con committed
216

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    You can use the project tree in the following ways:
    \list
        \o Right-clicking an item in the project tree brings up a
           context menu containing the actions most commonly needed.
           For example, through the menu of the project root directory you can,
           among other actions, build, re-build, clean and run the project.
        \o To list all files in a project, click
           \inlineimage qtcreator-filter.png
           and select \gui{Simplify tree}.
        \o During a build, the build system automatically generates source
           files. To hide these files, click \inlineimage qtcreator-filter.png
           and select \gui{Hide generated files}.
        \o To toggle the synchronization of your project tree with the file
           opened in the editor, click
           \inlineimage qtcreator-synchronizefocus.png
           .
        \o To see the absolute path of a file, move the mouse pointer over the
           file name.
con's avatar
con committed
235 236 237 238 239
    \endlist


    \section1 The Output Panes

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
240
    The task pane in Qt Creator can display one of the following panes:
241
    \gui{Build Issues}, \gui{Search Results}, \gui{Application Output}, and
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
242 243
    \gui{Compile Output}. Output panes are available in all
    \l{Qt Creator modes}{modes}.
con's avatar
con committed
244

245

246
    \section2 Build Issues
con's avatar
con committed
247

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
248 249 250
    The \gui{Build Issues} pane provides a list of errors and warnings
    encoutered during a build. The pane filters out irrelevant output from
    the build tools and presents the issues in an organized way.
con's avatar
con committed
251

252
    \image qtcreator-build-issues.png
con's avatar
con committed
253

254

con's avatar
con committed
255 256
    \section2 Search Results

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
257 258 259 260
    The \gui{Search Results} pane displays the results for global searches
    such as searching within a current document, files on disk, or all
    projects. The figure below shows an example output of search result for all
    occurrences of \c textfinder within the \c "/TextFinder" directory.
con's avatar
con committed
261 262 263

    \image qtcreator-search-pane.png

264

con's avatar
con committed
265 266
    \section2 Application Output

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
267
    The \gui{Application Output} pane displays the status of a program when
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
268 269
    it is executed, and the debug output. The figure below shows an example
    output from qDebug().
con's avatar
con committed
270 271 272

    \image qtcreator-application-output.png

273

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
274
    \section2 Compile Output
con's avatar
con committed
275

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
276 277
    The \gui{Compile Output} pane provides all output from the compiler. In
    other words, it is a more detailed version of information displayed in the
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
278
    \gui{Build Issues} pane.
con's avatar
con committed
279 280 281

    \image qtcreator-compile-pane.png

282

con's avatar
con committed
283 284 285
    \section1 Qt Help Integration

    Qt Creator comes fully integrated with all of Qt's documentation and
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
286
    examples using the Qt Help plugin.
con's avatar
con committed
287

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
288
    To view documentation, switch to \gui Help mode.
con's avatar
con committed
289

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
290 291 292 293
    To obtain context sensitive help, move the text cursor to a Qt class or
    function and press \key F1. The documentation is displayed in a pane
    next to the code editor, or, if there is not enough vertical space, in the
    fullscreen \gui Help mode.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
294

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
295
    \image qtcreator-context-sensitive-help.png
con's avatar
con committed
296

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
297 298
    To select and configure how the documentation is displayed in the
    \gui Help mode, select \gui Tools > \gui Options... > \gui Help.
con's avatar
con committed
299

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
300
    \section2 Adding External Documentation
con's avatar
con committed
301

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
302 303 304 305 306 307 308 309 310 311 312 313
    You can display external documentation in Qt Creator's \gui Help mode.
    To augument or replace the documentation that ships with Qt Creator and Qt:
    \list 1
        \o Create a .qch file from your documentation.

           For information on how to prepare your documentation and create a
           .qch file, see
           \l http://doc.qt.nokia.com/4.6/qthelp-framework.html
           {The Qt help framework}.
        \o Add the .qch file to Qt Creator by selecting \gui Tools >
           \gui Options... > \gui Help > \gui Documentation > \gui Add.
    \endlist
con's avatar
con committed
314 315 316


    \section1 Keyboard Navigation
317

318 319 320
    Qt Creator caters not only to developers who are used to using the mouse,
    but also to developers who are more comfortable with the keyboard. A wide
    range of \l{keyboard-shortcuts}{keyboard} and
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
    \l{Searching With the Locator}{navigation} shortcuts are available to help
    speed up the process of developing your application.


    \section1 Qt Designer Integration

    To help you design the user interface of your application, a complete
    version of Qt Designer is integrated right into Qt Creator. Qt Creator
    automatically opens all .ui files in Qt Designer.

    The Qt Designer integration includes project management and code
    completion.

    \image qtcreator-formedit.png

    To change the layout of Qt Designer user interface elements:
    \list 1
        \o Select \gui Tools > \gui{Form editor} > \gui Views >
           \gui Locked.

           When this option is unchecked, you can change the layout.
        \o Click the header of an element and drag the element to a new
           position.
    \endlist

    To change Qt Designer properties, select \gui Tools > \gui Options >
    \gui Designer.
    \list
        \o Set the class properties and code generation preferences in \gui
           {Class Generation}.
        \o Set an additional folder for saving templates in \gui{Template
           Paths}.
        \o Set the grid settings and preview preferences in \gui Forms. To
           preview your form with skins, enable \gui{Print/Preview
           Configuration} and select your skin. Otherwise default preview
           settings are used.

           To preview the settings, select \gui Tools > \gui{Form Editor} >
           \gui Preview, or press \key Ctrl+Alt+R.
        \o To specify embedded device profiles, such as style, font, and screen
           resolution, select \gui{Embedded Design}.
    \endlist

    For more information on Qt Designer, see
    \l{http://doc.trolltech.com/designer-manual.html}{Qt Designer Manual}.
con's avatar
con committed
366 367
*/

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
368

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
369 370
/*!
    \contentspage index.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
371
    \previouspage creator-writing-program.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
372 373
    \page creator-editor-using.html
    \nextpage creator-editor-finding.html
374

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
375
    \title Using the Editor
376

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
377 378 379 380
    Qt Creator's code editor is designed to aid you in creating, editing and
    navigating code. It is fully equipped with syntax checking, code
    completion, context sensitive help and in-line error indicators while you
    are typing.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
381 382


Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
    \section1 Configuring the Editor

    Qt Creator allows you to configure the text editor to suit your specific
    needs. To configure the editor, select  \gui Tools > \gui Options >
    \gui{Text Editor}:
    \list
        \o Set the font preferences and apply syntax highlighting in
           \gui{Font & Colors}.
        \o Set tabs, indentation and the handling of whitespace in
           \gui Behavior.
        \o Set various display properties, such as
           \l{Highlighting and folding blocks}{highlighting and folding blocks},
           text wrapping or \l{Moving to symbol definition or declaration}
           {moving to symbol definition or declaration}
           in \gui Display.
        \o Enable \l{Code completion}{code completion} in \gui Completion.
    \endlist


    \section1 Using the Editor Toolbar

    The editor toolbar is located at the top of the editor view. It is context
    sensitive and shows items relevant to the file currently open in the
    editor.

    \image qtcreator-editortoolbar-symbols.png

    Use the toolbar to navigate between open files and symbols in use:
    \list
        \o To browse the history of edits for the currently open session, click
           \inlineimage qtcreator-back.png
           and \inlineimage qtcreator-forward.png
           .
        \o To go to any open file, select it from the \gui{Open files}
           drop-down menu.
        \o To jump to any symbol used in the current file, select it from the
           \gui Symbols drop-down menu.
    \endlist

    When you create or edit forms in an .ui file, the toolbar contains
    Qt Designer specific tools.

    If you are using a version control system, the toolbar enables you to
    compare the current file with the version in the repository. For more
    information on using Qt Creator with version control systems, see
    \l{Using version control systems}.


    \section1 Splitting the Editor View

    Split the editor view when you want to work on and view multiple files on
    the same screen.

    \image qtcreator-spliteditorview.png

    You can split the editor view in two ways:
    \list
        \o To split the editor view into a top and bottom view, select
           \gui Window > \gui Split or press \key{Ctrl+E, 2}.

           Split command creates views below the currently active editor view.
        \o To split the editor view into adjacent views, select
           \gui Window > \gui{Split Side by Side} or press
           \key{Ctrl+E, 3}.

           Side by side split command creates views to the right of the
           currently active editor view.
    \endlist

    To move between split views, select \gui Window >
    \gui{Go to Other Split} or press \key{Ctrl+E, 0}.

    To remove a split view, place the cursor within the view you want to
    remove and select \gui Window > \gui{Remove Current Split} or press
    \key{Ctrl+E, 0}. To remove all but the currently selected split view,
    select \gui Window > \gui{Remove All Splits} or press \key{Ctrl+E, 1}.


    \section1 Highlighting and Folding Blocks

    Use block highlighting to visually separate parts of the code that belong
    together. For example, when you place the cursor within the braces,
    the code enclosed in braces is highlighted.

    \image qtcreator-blockhighlighting.png

    To enable block highlighting, select \gui Tools > \gui Options >
    \gui{Text Editor} > \gui Display > \gui{Highlight blocks}.

    Use the folding markers to collapse and expand blocks of code within
    braces. Click the folding marker to collapse or expand a block. In the
    figure above, the folding markers are located between the line number and
    the text pane.

    To show the folding markers, select \gui Tools > \gui Options >
    \gui{Text Editor} > \gui Display > \gui{Display folding markers}.


    \section1 Syntax Checking

    As you write code Qt Creator checks code syntax. When it spots syntax error
    in your code it underlines it and shows error details when you move the
    mouse pointer over the error:
    \list
        \o Syntax errors are underlined in red.

           In the following figure, semicolon is missing at the end of line.

           \image qtcreator-syntaxerror.png
        \o Semantic errors and warnings are underlined in olive.

           In the following figure, the type is unknown.

           \image qtcreator-semanticerror.png
    \endlist
498 499


500 501
    \section1 Code Completion

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
    As you write code Qt Creator provides a list of context-sensitive
    suggestions to the statement where your cursor is.

    \image qtcreator-codecompletion.png

    Set code completion preferences in \gui Tools > \gui Options >
    \gui{Text Editor} > \gui Completion.

    Qt Creator can complete common prefixes before showing a list of
    suggestions. This is especially useful for the classes with several
    similarly named members. To use this functionality, in the code
    completion preferences enable \gui{Autocomplete common prefix}.

    The following table lists available types for code completion and icon
    used for each.
517 518

    \table
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
519 520 521
        \header
            \o Icon
            \o Description
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
        \row
            \i  \inlineimage completion/class.png
            \i  A class
        \row
            \i  \inlineimage completion/enum.png
            \i  An enum
        \row
            \i  \inlineimage completion/enumerator.png
            \i  An enumerator (value of an enum)
        \row
            \i  \inlineimage completion/func.png
            \i  A function
        \row
            \i  \inlineimage completion/func_priv.png
            \i  A private function
        \row
            \i  \inlineimage completion/func_prot.png
            \i  A protected function
        \row
            \i  \inlineimage completion/var.png
            \i  A variable
        \row
            \i  \inlineimage completion/var_priv.png
            \i  A private variable
        \row
            \i  \inlineimage completion/var_prot.png
            \i  A protected variable
        \row
            \i  \inlineimage completion/signal.png
            \i  A signal
        \row
            \i  \inlineimage completion/slot.png
            \i  A slot
        \row
            \i  \inlineimage completion/slot_priv.png
            \i  A private slot
        \row
            \i  \inlineimage completion/slot_prot.png
            \i  A protected slot
        \row
            \i  \inlineimage completion/keyword.png
            \i  A keyword
        \row
            \i  \inlineimage completion/macro.png
            \i  A macro
        \row
            \i  \inlineimage completion/namespace.png
            \i  A namespace
    \endtable
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
571 572


Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
573 574 575 576 577 578 579 580
    \section1 Moving to Symbol Definition or Declaration

    In Qt Creator you can move directly to the definition or the declaration of
    a symbol by holding the \key Ctrl and clicking the symbol.

    To enable this function, in \gui Tools > \gui Options >
    \gui{Text Editor} > \gui Display select \gui{Enable mouse navigation}.

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
581

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
    \section1 Using an External Editor

    To open the file you are currently viewing in an external editor, select
    \gui Edit > \gui Advanced > \gui{Open in External Editor}.

    To use the external editor of your choice:
    \list 1
        \o On Windows add the editor path to the \bold Path system variable.
           On Linux and Mac OS X add the editor path to the \bold PATH
           environment variable.
        \o In Qt Creator select \gui Tools > \gui Options... >
           \gui Environment > \gui General.
        \o In \gui{External editor} enter the name of the application followed
           by \key Space and \tt{\bold %f}. For example, to open the file in
           Smultron, enter \tt{\bold{smultron %f}}

           To further define how to open the file in the external editor, you
           can use the following variables separated by space:
           \list
            \o Current line number \tt{\bold %l}
            \o Current column number \tt{\bold %c}
            \o Editor's x position on the screen \tt{\bold %x}
            \o Editor's y position on the screen \tt{\bold %y}
            \o Editor's width in pixels \tt{\bold %w}
            \o Editor's height in pixels \tt{\bold %h}
            \o Editor's width in characters \tt{\bold %W}
            \o Editor's height in characters \tt{\bold %H}
            \o To pass % symbol to the editor \tt{\bold %%}
           \endlist

           \note Not all variables work with all editors.
    \endlist
614 615 616
*/


con's avatar
con committed
617 618
/*!
    \contentspage index.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
619 620 621
    \previouspage creator-editor-using.html
    \page creator-editor-finding.html
    \nextpage creator-editor-refactoring.html
con's avatar
con committed
622

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
623
    \title Finding and Replacing
con's avatar
con committed
624

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
625 626 627 628 629 630 631 632 633 634 635 636
    To search through the currently open file:
    \list 1
        \o Press \key Ctrl+F or select \gui Edit > \gui Find/Replace >
           \gui{Current Document}.
        \o Enter the text you are looking for.

           If the text is found, all occurrences are highlighted as you type.
        \o To go to the next occurrence, click \inlineimage qtcreator-next.png
           , or press \key F3. To go to the previous occurrence click
           \inlineimage qtcreator-previous.png
           , or press \key Shift+F3.
    \endlist
con's avatar
con committed
637

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
    To narrow your search results, click
    \inlineimage qtcreator-locator-magnify.png
    in the \gui Find/Replace pane and select any of the following
    preferences:
    \list
        \o To make your search case sensitive, select
           \inlineimage qtcreator-editor-casesensitive.png
           .
        \o To search only whole words, select
           \inlineimage qtcreator-editor-wholewords.png
           .
        \o To search using regular expressions, select
           \inlineimage qtcreator-editor-regularexpressions.png
           .
           Regular expressions used in Qt Creator are modeled on Perl's regular
           expressions. For more information on using regular expressions, see
           \l http://doc.qt.nokia.com/4.6/qregexp.html#details
           {Detailed description of QRegExp class reference}.
    \endlist
con's avatar
con committed
657

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
658 659 660 661 662 663 664 665 666 667 668
    To replace occurrences of the existing text, enter the new text in the
    \gui{Replace with} text box.
    \list
        \o To replace the selected occurrence and move to the next one,
           click \inlineimage qtcreator-next.png
           or press \key Ctrl+=.
        \o To replace the selected occurrence and move to the previous one,
           click \inlineimage qtcreator-previous.png
           .
        \o To replace all occurrences in the file, click \gui{Replace All}.
    \endlist
con's avatar
con committed
669

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
670
    \section1 Advanced Search
con's avatar
con committed
671

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
    To search through projects, files on a file system or the currently open
    file:
    \list 1
        \o Press \key Ctrl+Shift+F or select \gui Edit >
           \gui Find/Replace > \gui Find....
        \o Select the scope of your search:
           \list
            \o \gui{All Projects} searches files matching the defined file
               pattern in all currently open projects.

               For example, to search for \tt previewer only in \tt .cpp
               and \tt .h files, enter in \gui{File pattern}
               \tt *.cpp,*.h.

               \image qtcreator-search-allprojects.png

            \o \gui{Current Project} searches files matching the defined file
               pattern only in the project you are currently editing.
            \o \gui{Files on File System} recursively searches files matching
               the defined file pattern in the selected directory.
            \o \gui{Current File} searches only the current file.
           \endlist
        \o Enter the text you are looking for and click \gui Search.

           \image qtcreator-searchresults.png

           A list of files containing the searched text is displayed in the
           \gui{Search Results} pane.
           \list
            \o To see all occurrences in a file, double-click the file name in
               the list.
            \o To go to an occurrence, double-click it.
           \endlist
    \endlist
*/
con's avatar
con committed
707 708


Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
709 710 711 712 713
/*!
    \contentspage index.html
    \previouspage creator-editor-finding.html
    \page creator-editor-refactoring.html
    \nextpage creator-editor-locator.html
con's avatar
con committed
714

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
715
    \title Refactoring
716

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
717 718 719 720 721 722 723 724 725
    Code refactoring is the process of changing the code without modifying the
    existing functionality of your application. By refactoring your code you
    can:
    \list
        \o Improve internal quality of your application
        \o Improve performance and extensibility
        \o Improve code readability and maintainability
        \o Simplify code structure
    \endlist
con's avatar
con committed
726

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
727
    \section1 Finding Symbols
con's avatar
con committed
728

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
    To find the use of a specific symbol in your project:
    \list 1
        \o In the editor place the cursor on the symbol and select \gui Tools
           > \gui C++ > \gui{Rename Symbol under Cursor} or press
           \key Ctrl+Shift+U.

           Qt Creator looks for the symbol in the following locations:
           \list
            \o Files listed as a part of the project
            \o Files directly used by the project files (for example, generated
               files)
            \o Header files of used frameworks and libraries
           \endlist
        \o The \gui{Search Results} pane opens and shows the location and
           number of instances of the symbol in the current project.

           \image qtcreator-refactoring-find.png
    \endlist
con's avatar
con committed
747

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
    You can browse the search results in the following ways:
    \list
        \o To go directly to an instance, double-click the instance in the
           \gui{Search Results} pane.
        \o To move between instances, click
           \inlineimage qtcreator-forward.png
           and
           \inlineimage qtcreator-back.png
           in the \gui{Search Results} pane.
        \o To expand and collapse the list of all instances, click
           \inlineimage qtcreator-expand.png
           .
        \o To clear the search results, click \inlineimage qtcreator-clear.png
           .
    \endlist
763

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
764 765 766
    \section1 Renaming Symbols

    To rename a specific symbol in your project:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
767
    \list 1
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
        \o In the editor, place the cursor on the symbol you would like to
           change and select \gui Tools > \gui C++ >
           \gui{Rename Symbol under Cursor} or press \key Ctrl+Shift+R.

           The \gui{Search Results} pane opens and shows the location and
           number of instances of the symbol in the current project.

           \image qtcreator-refactoring-replace.png
        \o To replace all selected instances, enter the name of the new symbol
           in the \gui{Replace with} text box and click \gui Replace.

           To omit an instance, uncheck the check-box next to the instance.

           \note This action replaces all selected instances of the symbol in
           all files listed in the \gui{Search Results} pane. You cannot
           undo this action.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
784
    \endlist
785 786
*/

787

788 789
/*!
    \contentspage index.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
790 791 792 793 794
    \previouspage creator-editor-locator.html
    \page creator-project-managing.html
    \nextpage creator-project-creating.html

    \title Managing Projects
con's avatar
con committed
795

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
796 797 798 799 800 801 802 803 804 805 806
    Qt Creator allows you to deploy various types of projects and provides a
    platform to work on different types of projects:
    \list
       \o To work with \bold{qmake projects}, open a \c .pro file. For more
          information, see \l{Setting Up a qmake Project}.
       \o To work with \bold{CMake projects} you need to have CMake version
          2.8.0 or later installed. For more information, see
          \l{Setting Up a CMake Project}.
       \o Qt Creator supports generic projects. For more information, see
          \l{Setting Up a Generic Project}.
    \endlist
con's avatar
con committed
807

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
808
    \section1 External Libraries
con's avatar
con committed
809

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
810 811 812
    Through external libraries Qt Creator can support code completion and
    syntax highlighting for external libraries as if they were a part of the
    current project or the Qt library.
con's avatar
con committed
813

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
814 815
    The procedure of adding a library to a project depends on the type of
    project, which influences the build system used.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
816

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
817 818 819 820 821 822 823 824 825 826 827 828 829 830
    \list
       \o For information on adding external libraries to qmake projects, see
          \l{Adding External Libraries to a qmake Project}.
       \o For information on adding external libraries to CMake projects, see
          \l{Adding External Libraries to a CMake Project}.
       \o For information on adding external libraries to generic projects, see
          \l{Adding External Libraries to a Generic Project}.
   \endlist

    \section1 Session Management
    In Qt Creator a session is a collection of bookmarks, breakpoints and
    watchers and can include multiple open projects. To learn about using and
    managing sessions, see \l{Managing Sessions}.
*/
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
831

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
832

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
833 834 835 836 837
/*!
    \contentspage index.html
    \previouspage creator-project-managing.html
    \page creator-project-creating.html
    \nextpage creator-project-qmake.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
838

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
839
    \title Creating a Project
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
840

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
841 842 843 844
    To create a new project:
    \list 1
        \o Select \gui File > \gui{New Project} and select the type of your
           project.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
845

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
846
           This example uses \bold{Qt4 Gui Application}.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
847

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
848 849 850
           \image qtcreator-new-project.png
        \o Name the project and set its path. To select the path from a
           directory tree, click \gui Choose....
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
851

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
852 853 854 855 856
           Avoid using spaces and special characters in the project name and
           path.

           \image qtcreator-intro-and-location.png
        \o Select the Qt modules you want to include in your project.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
857

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
           Since this example shows creation of a Qt4 Gui Application project
           type, QtCore and QtGui modules are selected by default. However, you
           can select any other you need.

           \image qtcreator-select-modules.png
        \o Specify the name of the class you want to create and using the
           drop-down menu select its base class type.

           Note that the \gui{Header file}, \gui{Source file} and
           \gui{Form file} fields are automatically updated as you name your
           class.

           \image qtcreator-class-info.png
        \o Review the project settings.

           To create the project, click \gui Done.

           \image qtcreator-new-project-summary.png
    \endlist
con's avatar
con committed
877 878
*/

879

con's avatar
con committed
880 881
/*!
    \contentspage index.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
882 883 884
    \previouspage creator-project-creating.html
    \page creator-project-qmake.html
    \nextpage creator-project-cmake.html
con's avatar
con committed
885

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
886
    \title Setting Up a qmake Project
con's avatar
con committed
887

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
    \section1 Selecting the Qt Version

    Qt Creator allows you to have multiple versions of Qt installed on
    your computer and use different versions for your projects.

    If Qt Creator finds \bold qmake in the PATH environment variable, it uses
    that version. This \l{glossary-system-qt}{version of Qt} is referred to as
    \bold{Qt in PATH}. If you intend to use only one version of Qt and it is
    already in the PATH and correctly set up for command line use, you do not
    need to manually configure your Qt version.

    \note By default, Qt Creator compiles projects with the
    \l{glossary-default-qt}{default Qt version}. For information on how to
    override this setting, see \l{Build Settings}.

    \section2 Windows

    To add a Qt version for \bold MinGW:
    \list 1
        \o Select \gui Tools > \gui Options... > \gui Qt4 >
           \gui{Qt Versions}.
        \o Click \inlineimage qtcreator-windows-add.png
           and enter the name of the version in \gui{Version Name} field.
        \o Enter the qmake binary path in the \gui{qmake Location}.
        \o Enter the MinGW installation path in the \gui{MinGW Directory}.

           \image qtcreator-qt4-qtversions-win-mingw.png
    \endlist

    To add a Qt version for a \bold{Microsoft Visual C++} compiler:
    \list 1
        \o Select \gui Tools > \gui Options... > \gui Qt4 >
           \gui{Qt Versions}.
        \o Qt Creator automatically sets the correct environment variables for
           compilation. Select the internal version number of the installed
           Microsoft Visual C++ tool chains using the \gui MSVC drop-down
           box:
           \list
               \o \bold 7.1 for Visual Studio 2003
               \o \bold 8.0 for Visual Studio 2005
               \o \bold 9.0 for Visual Studio 2008
           \endlist

           \note If you are using the
           \bold{Windows SDK for Windows Server 2008}, Qt Creator identifies
           it as version 9.0.

           \image qtcreator-qt4-qtversions-win-msvc.png
    \endlist

    If you are using \bold{Qt for Symbian} and your S60 SDK is registered
    with devices.exe, Qt Creator automatically detects the Qt version. To add a
    Qt for Symbian version:
    \list 1
        \o Select \gui Tools > \gui Options... > \gui Qt4 >
           \gui{Qt Versions}.
        \o Select the \gui{S60 SDK} you want the Qt Creator to use.

           \image qtcreator-qt4-qtversions-win-symbian.png
        \o To build an application for your device using GCCE, enter the path
           to the \bold{CSL ARM Toolchain} directory in
           \gui{CSL\\GCCE Directory}.

           You do not need to specify this path if the compiler is included in
           the PATH environment variable.
        \o To build an application for the emulator (WINSCW toolchain), enter
           the path to your Carbide C++ installation directory in
           \gui{Carbide Directory}.

           You need to have Carbide C++ version 2.0 or later installed.
    \endlist

    \section2 Linux
con's avatar
con committed
961

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
962 963 964
    To compile a project in Qt Creator, Linux uses GNU Compiler Collection
    (GCC). Intel Compiler Collection (ICC) is supported as a drop-in
    replacement for GCC.
965

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
    To add a Qt version:
    \list 1
        \o Select \gui Tools > \gui Options... > \gui Qt4 >
           \gui{Qt Versions}.
        \o Click \inlineimage qtcreator-linux-add.png
           and enter the name of the version in \gui{Version Name}.
        \o Enter the path to the qmake binary in \gui{Path to qmake}.
    \endlist

    \section2 Mac OS X

    To compile a project in Qt Creator, Mac OS X uses GNU Compiler Collection
    (GCC), which is part of Xcode.

    To add a Qt version:
    \list 1
        \o Select \gui{Qt Creator} > \gui Preferences... > \gui{Qt Versions}.
        \o Click \inlineimage qtcreator-macosx-add.png
           and enter the name of the version in \gui{Version Name}.
        \o Enter the path to the qmake binary in \gui{Path to qmake}.

           \image qtcreator-qt4-qtversions.png
    \endlist


    \section1 Setting Up a Project

    To view and modify the settings for currently open projects, switch to the
    \gui Projects mode by pressing \key Ctrl+4.

    \image qtcreator-projectpane.png

    The project pane consists of three tabs
    \list
       \o Targets
       \o Editor Settings
       \o Dependencies
    \endlist

    Use the \gui Build and \gui Run buttons on *Desktop* to switch between
    the build and run settings for the active project.

    If you have multiple projects open in Qt Creator, use
    \gui{Select a Project} option at the top to navigate between different
    project edits.

    \section1 Build Settings

    Different build configurations allow you to quickly switch between
    different build settings. By default, Qt Creator creates \bold debug
    and \bold release build configurations. Both of these configurations use
    the \l{glossary-default-qt}{default Qt version}.

    \image qtcreator-ppbuildsettings.png

    \section2 Adding and Removing Build Configurations

    To add a new build configuration, click \gui Add and select the type of
    configuration you would like add. You can add as many build configurations
    as you need.

    To delete the build configuration currently selected, click \gui Remove.

    \section2 Editing Build Configurations

    To edit a build configuration:
    \list 1
        \o Select the build configuration you want to edit in
           \gui{Edit Build Configuration}.
        \o In section \gui General, you can specify:
1036
        \list
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1037 1038 1039 1040 1041 1042 1043
            \o The \l{glossary-project-qt}{Qt version} you want to use to
               build your project. For more information, see
               \l{Selecting the Qt version}.
            \o The toolchain required to build the project.
            \o If you want to \l{glossary-shadow-build}{shadow build} your
               project, check the \gui{Shadow Build} checkbox and select the
               build directory.
1044
        \endlist
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1045
    \endlist
con's avatar
con committed
1046

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1047
    \section2 Build Steps
con's avatar
con committed
1048

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1049 1050 1051 1052
    The build system of Qt Creator is built on qmake and make. In
    \gui{Build Steps} you can change the settings for qmake and make. Qt
    Creator runs the make command using the Qt version defined for the current
    build configuration.
con's avatar
con committed
1053

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1054
    \section2 Clean Steps
con's avatar
con committed
1055

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1056 1057 1058
    The cleaning process is used to remove intermediate files. This process
    might help you to fix obscure issues during the process of building a
    project.
con's avatar
con committed
1059

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
    You can define the cleaning steps for your builds in the \gui{Clean Steps}:
    \list
        \o To add a clean step using make or a custom process, click
           \gui{Add clean step} and select the type of step you want to add.

           By default, custom steps are disabled. Activate customs steps by
           checking the \gui{Enable Custom Process Step} check-box.
        \o To remove a clean step, click \gui{Remove clean step} and select the
           step you want to remove.
        \o To change the order of steps, click
           \inlineimage qtcreator-movestep.png
           .
    \endlist
con's avatar
con committed
1073

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1074
    \section2 Build Environment
con's avatar
con committed
1075

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1076 1077 1078 1079 1080 1081 1082
    You can specify the environment you want to use for building in the
    \bold{Build Environment} section. By default, the environment in which Qt
    Creator was started is used and modified to include the Qt version.
    Depending on the selected Qt version, Qt Creator automatically sets the
    necessary environment variables. You can edit existing environment
    variables or add, reset and unset new variables based on your project
    requirements.
con's avatar
con committed
1083 1084


Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1085
    \section1 Run Settings
con's avatar
con committed
1086

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1087 1088 1089 1090
    Qt Creator automatically creates run configurations for your project.
    These run configurations derive their executable from the parsed .pro
    files. You can also create custom executable run configurations where you
    can set the executable to be run.
1091

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1092
    \image qtcreator-pprunsettings.png
1093

1094

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
    \section1 File Encoding

    To define the default file encoding, select the desired encoding in the
    \gui{Editor Settings}. By default, the Qt Creator uses the file encoding
    used by your system.


    \section1 Dependencies

    If you have multiple projects loaded in your session, you can define the
    dependencies between them. This affects the build order of your
    projects.

    \note These dependencies are unrelated to the dependencies inside a qmake
    project.

    To define the dependencies:
    \list 1
        \o Select the project for which you want to configure dependencies.
        \o In the \gui Dependencies section check the checkboxes to select
           other projects as dependencies.
    \endlist


    \section1 Adding External Libraries to a qmake Project

    Through external libraries Qt Creator can support code completion and
    syntax highlighting as if they were part of the current project or the Qt
    library.

    To add an external library:
    \list
        \o Open your project file (.pro) using the \gui Projects pane.
        \o Follow the instructions at \l http://doc.trolltech.com/latest/qmake-project-files.html#declaring-other-libraries
           {Declaring other Libraries}.
    \endlist
1131

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1132 1133
    Syntax completion and highlighting work once your project successfully
    builds and links against the external library.
con's avatar
con committed
1134 1135
*/

1136

con's avatar
con committed
1137 1138
/*!
    \contentspage index.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1139
    \previouspage creator-quick-tour.html
con's avatar
con committed
1140
    \page creator-writing-program.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1141
    \nextpage creator-editor-using.html
con's avatar
con committed
1142

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1143
    \title Writing a Simple Program
con's avatar
con committed
1144

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1145 1146 1147
    \note This tutorial assumes that you have experience in writing basic Qt
    applications, using Qt Designer to design user interfaces and using the Qt
    Resource System.
con's avatar
con committed
1148

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1149
    In this example, we describe the steps involved in using Qt Creator
con's avatar
con committed
1150 1151
    to create a small Qt program, Text Finder. Inspired by the QtUiTools'
    \l{http://doc.trolltech.com/uitools-textfinder.html}{Text Finder}
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1152
    example, we write a similar but simplified version of it, as shown
con's avatar
con committed
1153 1154 1155 1156 1157 1158
    below.

    \image qtcreator-textfinder-screenshot.png

    \section1 Setting Up Your Environment

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1159 1160
    Once you have installed Qt Creator, it detects automatically if Qt's
    location is in your \c PATH variable. If not, please follow the
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1161
    instructions in \l{Selecting the Qt version}.
con's avatar
con committed
1162

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1163
    \section1 Setting Up the Project
con's avatar
con committed
1164 1165

    We begin with a Qt4 Gui Application project generated by Qt Creator. The
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1166
    \l{Creating a project} document describes this process in
1167
    detail. Remember to select QWidget as the Text Finder's base class. If
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1168
    your project is not yet loaded, load it by selecting \gui{File} > \gui{Open}.
con's avatar
con committed
1169

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1170
    In your project, you have the following files:
con's avatar
con committed
1171 1172 1173 1174 1175 1176 1177 1178

    \list
        \o \c{textfinder.h}
        \o \c{textfinder.cpp}
        \o \c{main.cpp}
        \o \c{textfinder.ui}
        \o \c{textfinder.pro}
    \endlist
1179

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1180 1181
    The \c{.h} and \c{.cpp} files come with the necessary boiler plate code.
    The \c{.pro} file is also complete.
con's avatar
con committed
1182

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1183
    \section1 Filling in the Missing Pieces
con's avatar
con committed
1184

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1185 1186
    We begin by designing the user interface and then move on to filling
    in the missing code. Finally, we add the find functionality.
con's avatar
con committed
1187

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1188
    \section2 The User Interface
con's avatar
con committed
1189 1190

    To begin designing the user interface, double-click on the
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1191
    \c{textfinder.ui} file in the \gui{Project Explorer}. This launches the
con's avatar
con committed
1192 1193
    integrated Qt Designer.

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1194 1195 1196 1197 1198 1199 1200 1201
    Design the form below with:
    \list
        \o \l{http://doc.trolltech.com/qlabel.html}{QLabel}
        \o \l{http://doc.trolltech.com/qlinedit.html}{QLineEdit} (named lineEdit)
        \o \l{http://doc.trolltech.com/qpushbutton.html}{QPushButton} (named findButton)
        \o \l{http://doc.trolltech.com/qtextedit.html}{QTextEdit} (named textEdit)
    \endlist

con's avatar
con committed
1202 1203
    \image qtcreator-textfinder-ui.png

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1204 1205 1206 1207 1208 1209
    We recommend that you use a \l{http://doc.trolltech.com/qgridlayout.html}{QGridLayout}
    to lay out the label, the line edit and the push button.
    The grid layout and the text edit can then be added to a
    \l{http://doc.trolltech.com/qvboxlayout.html}{QVBoxLayout}.
    If you are new to designing forms with \QD, see the
    \l{http://doc.trolltech.com/designer-manual.html}{Qt Designer Manual}.
con's avatar
con committed
1210 1211 1212

    \section2 The Header File

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1213
    The \c{textfinder.h} file already has the necessary #includes, a
con's avatar
con committed
1214 1215 1216
    constructor, a destructor, and the \c{Ui} object. We need to add a private
    slot, \c{on_findButton_clicked()}, to carry out our find operation. We
    also need a private function, \c{loadTextFile()}, to read and display the
1217 1218 1219
    contents of our input text file in the
    \l{http://doc.trolltech.com/qtextedit.html}{QTextEdit}. This is done with
    the following code:
con's avatar
con committed
1220

1221
    \snippet examples/textfinder/textfinder.h 0
1222

1223
    \note The \c{Ui::TextFinder} object is already provided.
con's avatar
con committed
1224 1225 1226 1227

    \section2 The Source File

    Now that our header file is complete we move on to our source file,
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1228 1229
    \c{textfinder.cpp}. We begin by filling in the functionality to load a
    text file. This is described in the code snippet below:
con's avatar
con committed
1230

1231
    \snippet examples/textfinder/textfinder.cpp 0
con's avatar
con committed
1232

1233 1234 1235 1236
    Basically, we load a text file using
    \l{http://doc.trolltech.com/qfile.html}{QFile}, read it with
    \l{http://doc.trolltech.com/qtextstream.html}{QTextStream}, and
    then display it on \c{textEdit} with
hjk's avatar
hjk committed
1237 1238
    \l{http://doc.trolltech.com/qtextedit.html#plainText-prop}{setPlainText()}
    which requires adding the following additional #includes to textfinder.cpp:
1239 1240

    \snippet examples/textfinder/textfinder.cpp 1
con's avatar
con committed
1241 1242

    For the \c{on_findButton_clicked()} slot, we extract the search string and
1243
    use the \l{http://doc.trolltech.com/qtextedit.html#find}{find()} function
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1244 1245
    to look for the search string within the text file. This is described in
    the code snippet below:
con's avatar
con committed
1246

1247
    \snippet examples/textfinder/textfinder.cpp 2
con's avatar
con committed
1248

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1249
    Once we have both of these functions complete, we call \c{loadTextFile()} in
con's avatar
con committed
1250 1251
    our constructor.

1252
    \snippet examples/textfinder/textfinder.cpp 3
con's avatar
con committed
1253

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1254 1255
    The \c{on_findButton_clicked()} slot is called automatically in
    the uic generated \c{ui_textfinder.h} file by this line of code:
con's avatar
con committed
1256 1257

    \code
1258
    QMetaObject::connectSlotsByName(TextFinder);
con's avatar
con committed
1259 1260 1261 1262
    \endcode

    \section2 The Resource File

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1263 1264 1265 1266 1267 1268 1269 1270 1271
    We require a resource file (\c{.qrc}) within which we embed the input
    text file. This can be any \c{.txt} file with a paragraph of text.

    To add a resource file:
    \list 1
        \o Right-click on \gui{Resource Files} in the \gui{Project Explorer}.
        \o Select \gui{Add New File...}.
    \endlist
    The wizard dialog below is displayed.
con's avatar
con committed
1272 1273 1274

    \image qtcreator-add-resource-wizard.png

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1275 1276 1277 1278 1279
    \list 3
        \o Enter "textfinder" in the \gui{Name} field. Use the given \gui{Path}.
        \o Click on \gui{Continue}.
    \endlist
    This page is displayed:
1280 1281 1282

    \image qtcreator-add-resource-wizard2.png

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1283 1284 1285 1286 1287 1288
    \list 5
        \o Choose to which project you want to add the new file. Select "TextFinder"
        as the \gui{Project}.
        \o Make sure that \gui{Add to Project} is checked.
        \o Click on \gui{Done}.
    \endlist
con's avatar
con committed
1289

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1290
    Your resource file is now displayed in the resource editor.
con's avatar
con committed
1291

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1292 1293 1294 1295 1296 1297
    \list 8
        \o Select \gui{Add} > \gui{Add Prefix} from the drop-down list. The prefix we
        require is a slash (\c{/}).
        \o Select \gui{Add} > \gui{Add File} from the drop-down list.
        \o Locate the text file you are going to use. We use \c{input.txt}.
    \endlist
con's avatar
con committed
1298

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1299
    Once the resource file has been successfully added, the following is displayed:
con's avatar
con committed
1300

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1301
    \image qtcreator-add-resource.png
con's avatar
con committed
1302

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1303
    \section1 Compiling and Running Your Program
con's avatar
con committed
1304

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1305 1306
    Now that you have all the necessary files, click the \inlineimage qtcreator-run.png
    button to compile your program.
1307

con's avatar
con committed
1308 1309
*/