Skip to content
Snippets Groups Projects
qtcreator.qdoc 188 KiB
Newer Older
        \image qtcreator-new-project-summary.png "Project Management dialog"
        \o Review the project settings, and click \gui{Finish} to create the project.


    The TextFinder project now contains the following files:
con's avatar
con committed

    \list
        \o textfinder.h
        \o textfinder.cpp
        \o main.cpp
        \o textfinder.ui
        \o textfinder.pro
con's avatar
con committed
    \endlist
    \image qtcreator-textfinder-contents.png "TextFinder project contents"

    The .h and .cpp files come with the necessary boiler plate code.
    The .pro file is complete.
con's avatar
con committed

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

    Begin by designing the user interface and then move on to filling
    in the missing code. Finally, add the find functionality.
con's avatar
con committed

con's avatar
con committed

    \image qtcreator-textfinder-ui.png "Text Finder UI"
con's avatar
con committed

    \o In the \gui{Editor} mode, double-click the textfinder.ui file in the \gui{Projects}
    view to launch the integrated \QD.

    \o Drag and drop the following widgets to the form:
con's avatar
con committed

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \list
    \o \gui{Label} (\l{http://doc.trolltech.com/qlabel.html}{QLabel})
    \o \gui{Line Edit} (\l{http://doc.trolltech.com/qlineedit.html}{QLineEdit})
    \o \gui{Push Button} (\l{http://doc.trolltech.com/qpushbutton.html}{QPushButton})

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \endlist

    \image qtcreator-textfinder-ui-widgets.png "Adding widgets to Text Finder UI"

    \o Double-click the \gui{Label} widget and enter the text \bold{Keyword}.

    \o Double-click the \gui{Push Button} widget and enter the text \bold{Find}.
con's avatar
con committed

    \o Press \key {Ctrl+A} to select the widgets and click \gui{Lay out Horizontally}
    (or press \gui{Ctrl+H}) to apply a horizontal layout
    (\l{http://doc.trolltech.com/qhboxlayout.html}{QHBoxLayout}).

    \image qtcreator-texfinder-ui-horizontal-layout.png "Applying horizontal layout"

    \o Drag and drop a \gui{Text Edit} widget (\l{http://doc.trolltech.com/qtextedit.html}{QTextEdit})
    to the form.

    \o Select the screen area and click \gui{Lay out Vertically} (or press \gui{Ctr+V})
    to apply a vertical layout (\l{http://doc.trolltech.com/qvboxlayout.html}{QVBoxLayout}).

    \image qtcreator-textfinder-ui.png "Text Finder UI"
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \endlist

    Applying the horizontal and vertical layouts ensures that the application UI scales to different
    screen sizes.
con's avatar
con committed

    For more information about designing forms with \QD, see the
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \l{http://doc.trolltech.com/designer-manual.html}{Qt Designer Manual}.
con's avatar
con committed

con's avatar
con committed

    The textfinder.h file already has the necessary #includes, a
    constructor, a destructor, and the \c{Ui} object. You need to add a private
    slot, \c{on_findButton_clicked()}, to carry out the find operation. You
con's avatar
con committed
    also need a private function, \c{loadTextFile()}, to read and display the
    contents of the input text file in the
    \l{http://doc.trolltech.com/qtextedit.html}{QTextEdit}.

    \list 1

    \o In the \gui{Projects} view, double-click the \c{textfinder.h} file
    to open it for editing.

    \o Add a private slot in a \c{private slots} section and a private function
    in the \c{private} section, after the \c{Ui::TextFinder} function, as
    illustrated by the following code snippet:
con's avatar
con committed

    \snippet examples/textfinder/textfinder.h 0
con's avatar
con committed

con's avatar
con committed

    Now that the header file is complete, move on to the source file,
con's avatar
con committed

    \o In the \gui{Projects} view, double-click the textfinder.cpp file
con's avatar
con committed

    \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
    \l{http://doc.trolltech.com/qtextedit.html#plainText-prop}{setPlainText()}
    This is illustrated by the following code snippet:

    \snippet examples/textfinder/textfinder.cpp 0

    \o To use \l{http://doc.trolltech.com/qfile.html}{QFile} and
    \l{http://doc.trolltech.com/qtextstream.html}{QTextStream}, add the
    following #includes to textfinder.cpp:

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

    \o For the \c{on_findButton_clicked()} slot, add code to extract the search string and
    use the \l{http://doc.trolltech.com/qtextedit.html#find}{find()} function
    to look for the search string within the text file. This is illustrated by
    the following code snippet:
con's avatar
con committed

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

    \o Once both of these functions are complete, add a line to call \c{loadTextFile()} in
    the constructor, as illustrated by the following code snippet:
con's avatar
con committed

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

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

    \code
    QMetaObject::connectSlotsByName(TextFinder);
con's avatar
con committed
    \endcode

con's avatar
con committed

    You need a resource file (.qrc) within which you embed the input
    text file. The input file can be any .txt file with a paragraph of text.
    Create a text file called input.txt and store it in the textfinder
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

    To add a resource file:
    \list 1
        \o Select \gui{File > New File or Project > Qt > Qt Resource File > OK}.
    \image qtcreator-add-resource-wizard.png "New File or Project dialog"
con's avatar
con committed

    The \gui {Choose the Location} dialog opens.
con's avatar
con committed

        \image qtcreator-add-resource-wizard2.png "Choose the Location dialog"
        \o In the \gui{Name} field, enter \bold{textfinder}.
        \o In the \gui{Path} field, enter \c{C:\Qt\examples\TextFinder},
        and click \gui{Next}.
        The \gui{Project Management} dialog opens.
con's avatar
con committed

        \image qtcreator-add-resource-wizard3.png "Project Management dialog"
con's avatar
con committed


        \o In the \gui{Add to project} field, select \bold{TextFinder.pro}
        and click \gui{Finish} to open the file in the code editor.
con's avatar
con committed

        \o In the \gui{Prefix} field, replace the default prefix with a slash (/).
        \o Select \gui{Add > Add Files}, to locate and add input.txt.

        \image qtcreator-add-resource.png "Editing resource files"
con's avatar
con committed

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \endlist
con's avatar
con committed

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

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

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

con's avatar
con committed
/*!
    \contentspage index.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \previouspage creator-debugging.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \title Using Version Control Systems
    Version control systems supported by Qt Creator are:
        \header
            \i \bold{Version Control System}
            \i \bold{Address}
            \i \bold{Notes}
        \row
            \i  \bold{Subversion}
            \i  \l{http://subversion.tigris.org/}
            \i  Server version 2006.1 and later
        \row
            \i  \bold{CVS}
            \i  \l{http://www.cvshome.org}
            \i
        \row
            \i  \bold{Mercurial}
            \i  \l{http://mercurial.selenic.com/}
            \i  Qt Creator 2.0 and later
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \section1 Setting Up Version Control Systems
    Qt Creator uses the version control system's command line clients to access
    your repositories. To set up the version control system's command line
    clients to access your repositories, make sure that the command line clients
    can be located using the \c{PATH} environment variable or specify the path to
    the command line client executables, in the settings pages shown by
    \gui{Tools} > \gui{Options...}.
    \section1 Setting Up Common Options
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

    Select \gui{Tools} > \gui{Options...} > \gui{Version Control} > \gui{Common}
    to view the common settings for version control systems. The following are
    the options present in \gui{Common}:
    \list
       \o   \gui{Submit message checking script} is a script or program that
             can be used to perform checks on the submit message before
             submitting. The submit message is passed in as the script's first
             parameter. If there is an error, the script should output a
             message on standard error and return a non-zero exit code.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

       \o    \gui{User/alias configuration file} takes a file in mailmap format
             that lists user names and aliases. For example:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

             \code
             Jon Doe <Jon.Doe@company.com>
             Hans Mustermann <Hans.Mustermann@company.com> hm <info@company.com>
             \endcode
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

             \note The second line above specifies the alias \e{hm} and the
             corresponding email address for \e{Hans Mustermann}. If the
             user/alias configuration file is present, the submit editor
             displays a context menu with \gui{Insert name...} that pops up a
             dialog letting the user select a name.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

       \o    \gui{User fields configuration file} is a simple text file
             consisting of lines specifying submit message fields that take
             user names, for example:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

             \code
             Reviewed-by:
             Signed-off-by:
             \endcode
    \endlist
    The fields above appear below the submit message. They provide completion
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    for the aliases/public user names specified in the
    \e{User/alias configuration file} as well as a button that opens the
    aforementioned user name dialog.
    \section1 Creating VCS Repositories for New Projects

    Qt Creator allows for creating VCS repositories for version
    control systems that support local repository creation, such as
    \bold{git} or \bold{hg}.
    When creating a new project by selecting \gui File >
    \gui{New File or Project...}, you can choose a version
    control system in the final wizard page.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \section1 Using Version Control Systems
    The version control sub-menus are in \gui{Tools} > \gui{Options...}.
    The \gui{Version Control} page also displays the
    version control system managing the current project
    Under \gui{Application Output} > \gui{Version Control}, there is an output
    pane showing the commands that are executed, prepended by a
    timestamp and the relevant output.

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    When you create a new file or a new project, the wizard displays a page
    asking whether the files should be added to a version control system.
    This happens when the parent directory or the project is already
    under version control and the system supports the concept of adding files,
    for example, \bold{Perforce} and \bold{Subversion}. Alternatively, you can
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    add files later by using the version control tool menus.

    With \bold{git}, there is no concept of adding files. Instead, all modified
    files must be staged for a commit.


    \section2 Viewing Diff Output

    All version control systems provide menu options to \e{diff} the current
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    file or project: to compare it with the latest version stored in the
    repository and to display the differences. In Qt Creator, a diff is
    displayed in a read-only editor. If the file is accessible, you can
    double-click on a selected diff chunk and Qt Creator opens an editor
    displaying the file, scrolled to the line in question.

    \image qtcreator-vcs-diff.png


    \section2 Viewing Versioning History and Change Details

    Display the versioning history of a file by selecting \gui{Log}
    (for \bold{git}) or \gui{Filelog}(for \bold{Perforce} and
    \bold{Subversion}). Typically, the log output contains the date, the commit
    message, and a change or revision identifier. Click on the identifier to
    display a description of the change including the diff.
    Right-clicking on an identifier brings up a context menu that lets you
    show annotation views of previous versions (see \l{Annotating Files}).

    \image qtcreator-vcs-log.png
    \image qtcreator-vcs-describe.png


    \section2 Annotating Files

    Annotation views are obtained by selecting \gui{Annotate} or \gui{Blame}.
    Selecting \gui{Annotate} or \gui{Blame} displays the lines of the file
    prepended by the change identifier they originate from. Clicking on the
    change identifier shows a detailed description of the change.
    To show the annotation of a previous version, right-click on the
    version identifier at the beginning of a line and choose one of the
    revisions shown at the bottom of the context menu. This allows you to
    navigate through the history of the file and obtain previous versions of
    it. It also works for \gui git/hg using SHA's.
    The same context menu is available when right-clicking on a version
    identifier in the file log view of a single file.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed


    \section2 Committing Changes

    Once you have finished making changes, submit them to the version control
    system by choosing \gui{Commit} or \gui{Submit}. Qt Creator displays a
    commit page containing a text editor where you can enter your commit
    message and a checkable list of modified files to be included.

    When you have finished filling out the commit page information, click on
    \gui{Commit} to start committing.

    The \gui{Diff Selected Files} button brings up a diff view of the
    files selected in the file list. Since the commit page is just another
    editor, you can go back to it by closing the diff view. You can also check
    a diff view from the editor combo box showing the \gui{Opened files}.

    \image qtcreator-vcs-commit.png


Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

    \section2 Using git-specific Menu Entries

    The git sub-menu contains additional entries:

    \table
        \row
            \i  \gui{Stash snapshot...}
            \i  Allows you to save a snapshot of your current
                work under a name for later reference. For example, if you
                want to try out something and find out later that it does not work,
                you can discard it and return to the state of the snapshot.
        \row
            \i  \gui{Stash}
            \i  Stash local changes prior to executing a \bold{pull}.
        \row
            \i  \gui{Pull}
            \i  Pull changes from the remote repository. If there are locally
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
                modified files, you are prompted to stash those changes.
                The \bold{git} settings page contains an option to do
                a rebase operation while pulling.

        \row
            \i  \gui{Clean repository.../Clean project...}
            \i  Collect all files that are not under version control
                with the exception of patches and project files
                and show them as a checkable list in a dialog
                prompting for deletion. This lets you completely clean a build.

        \row
            \i  \gui{Branches...}
            \i  Displays the branch dialog showing the local branches at the
                top and remote branches at the bottom. To switch to the local
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
                branch, double-click on it. Double-clicking on a remote
                branch first creates a local branch with the same name that
                tracks the remote branch, and then switches to it.

                \image qtcreator-vcs-gitbranch.png


        \row
            \i  \gui{Stashes...}
            \i  Displays a dialog showing the stashes created by
                \gui{Stash snapshots...} with options to restore,
                display or delete them.
con's avatar
con committed
*/


Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \previouspage creator-editor-refactoring.html
    \page creator-editor-locator.html
    \nextpage creator-project-managing.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \title Searching With the Locator
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    The locator provides one of the easiest ways in Qt Creator to browse
    through projects, files, classes, methods, documentation and file systems.
    You can find the locator in the bottom left of the Qt Creator window.

    To activate the locator, press \key Ctrl+K (\key Cmd+K on Mac OS
    X) or select \gui Tools > \gui Locate....
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    To edit the currently open project's main.cpp file using the locator:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \list 1
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
        \o Activate the locator by pressing \key Ctrl+K.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

           \image qtcreator-locator-open.png
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
        \o Press \key Return.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

           The main.cpp file opens in the editor.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \endlist

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    It is also possible to enter only a part of a search string.
    As you type, the locator shows the occurrences of that string regardless
    of where in the name of an component it appears.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

    To narrow down the search results, you can use the following wildcard
    characters:
    \list
        \o To match any number of any or no characters, enter \bold{*}.
        \o To match a single instance of any character, enter \bold{?}.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \endlist
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \section1 Using the Locator Filters
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    The \gui Locator allows you to browse not only files, but any items
    defined by \bold{locator filters}. By default, the locator contains
    filters which locate:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
        \o  Any open document
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
        \o  Files belonging to your project, such as source, header resource,
            and .ui files
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
        \o  Class and method definitions in your project or anywhere referenced
            from your project
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
        \o  Help topics, including Qt documentation
        \o  Specific line in the document displayed in your editor
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    To use a specific locator filter, type the assigned prefix followed by
    \key Space. The prefix is usually a single character.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    For example, to locate symbols matching
    \l{http://doc.trolltech.com/qdatastream.html}{QDataStream:}
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \list 1
        \o Activate the locator.
        \o Enter \tt{\bold{: QDataStream}} (: (colon) followed by a
           \key Space and the symbol name (QDataStream)).
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
           The locator lists the results.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
           \image qtcreator-navigate-popup.png
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \endlist
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

    By default the following filters are enabled and you do not need to use
    their prefixes explicitly:
    \list
        \o Going to a line in the current file (l).
        \o Going to an open file (o).
        \o Going to a file in any open project (a).
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \endlist
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \section2 Using the Default Locator Filters

    The following locator filters are available by default:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Enter in locator
            \o  Example
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Go to a line in the current file.
            \o  \tt{\bold{l \e{Line number}}}
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Go to a symbol definition.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  \tt{\bold{: \e{Symbol name}}}
            \o  \image qtcreator-locator-symbols.png
        \row
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Go to a help topic.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  \tt{\bold{? \e{Help topic}}}
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Go to an open file.
            \o  \tt{\bold{o \e{File name}}}
            \o  \image qtcreator-locator-opendocs.png
        \row
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Go to a file in the file system (browse the file system).
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  \tt{\bold{f \e{File name}}}
            \o  \image qtcreator-locator-filesystem.png
        \row
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Go to a file in any project currently open.
            \o  \tt{\bold{a \e{File name}}}
            \o  \image qtcreator-locator-files.png
        \row
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Go to a file in the current project.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  \tt{\bold{p \e{File name}}}
            \o  \image qtcreator-locator-current-project.png
        \row
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Go to a class definition.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  \tt{\bold{c \e{Class name}}}
            \o  \image qtcreator-locator-classes.png
        \row
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  Go to a method definition.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o  \tt{\bold{m \e{Method name}}}
            \o  \image qtcreator-locator-methods.png
    \endtable

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \section2 Creating Locator Filters
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    To quickly access files not directly mentioned in your project, you can
    create your own locator filters. That way you can locate files in a
    directory structure you have defined.

    To create a locator filter:
    \list 1
        \o In the locator, click \inlineimage qtcreator-locator-magnify.png
           and select \gui Configure....

           \image qtcreator-locator-customize.png

        \o In the \gui{Options...} window click \gui Add.
        \o In the \gui{Filters} dialog:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
        \list
            \o Name your filter.
            \o Select at least one directory. The locator searches directories
               recursively.
            \o Define the file pattern as a comma separated list. For example,
               to search all .h and .cpp files, enter \bold{*.h,*.cpp}
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o Specify the prefix string.

               To show only results matching this filter, select
               \gui{Limit to prefix}.

               \image qtcreator-navigate-customfilter.png
        \endlist
        \o Click OK.
    \endlist

    \section3 Configuring the Locator Cache

    The locator searches the files matching your file pattern in the
    directories you have selected and caches that information. The cache for
    all default filters is updated as you write your code. The filters you have
    created Qt Creator by default updates once an hour.

    To update the cached information manually, click
    \inlineimage qtcreator-locator-magnify.png
    and select \gui Refresh.

    To set a new cache update time:
    \list 1
        \o Select \gui Tools > \gui Options... > \gui Locator.
        \o In \gui{Refresh interval} define new time in minutes.
    \endlist
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \previouspage creator-project-generic.html
    \page creator-project-managing-sessions.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \title Managing Sessions
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
        \o Open projects with their dependencies
        \o Open editors
        \o Breakpoints and watches
        \o Bookmarks
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    When you launch Qt Creator, a list of existing sessions is displayed on the
    \gui{Welcome screen}.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \image qtcreator-welcome-session.png
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    To switch between sessions, select the session from sessions listed in
    \gui File > \gui Session. If you do not create or select a session,
    Qt Creator always uses the default session.
    To create a new session or remove existing sessions, select \gui File >
    \gui Sessions > \gui{Session Manager}.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \image qtcreator-session-manager.png
con's avatar
con committed
/*!
    \contentspage index.html
    \previouspage creator-usability.html
con's avatar
con committed
    \page creator-debugging.html
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \nextpage creator-version-control.html
con's avatar
con committed

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \title Debugging
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \section1 About Debugging with Qt Creator
    Qt Creator does not have its own debugger. Qt Creator provides a graphical
    frontend to the following:
con's avatar
con committed

    \table
        \header
            \o Platform
            \o Compiler
            \o Debugger Engine
            \o Linux, Unixes, Mac OS
            \o gcc
            \o GNU Symbolic Debugger (gdb)
            \o Windows/MinGW
            \o gcc
            \o GNU Symbolic Debugger (gdb)
            \o Windows
            \o Microsoft Visual C++ Compiler
            \o Debugging Tools for Windows/Microsoft Console Debugger (CDB)
con's avatar
con committed
    \endtable

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    The frontend allows you to:
    \list
        \o Go through a program line-by-line or instruction-by-instruction.
        \o Interrupt running programs.
        \o Set breakpoints.
        \o Examine the contents of the call stack, local and global variables, etc.
    \endlist
con's avatar
con committed

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    Qt Creator displays the raw information provided by the engine
    in a clear and concise manner. This simplifies the debugging process.
con's avatar
con committed

    Qt Creator comes with generic IDE functionality: stack view, views for
    locals and watchers, registers, etc. In addition, Qt Creator includes
    features to make debugging Qt-based applications easy. The debugger
    frontend understands the internal layout of several Qt classes, for
    example, QString, the QTL containers, and most importantly QObject
    (and classes derived from it), as well as most containers of the C++
    Standard Library. The debugger can present its contents in a useful way.
con's avatar
con committed


    \section1 Debugger Engine Installation Notes

    \table
        \header
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o Debugger engine
            \o On Linux, install version 6.8, 7.0.1 (version 7.0 is not supported),
            7.1, or later. On Mac OS X, install Apple gdb version 6.3.x.

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
            \o Debugging tools for Windows
            \o Using this engine requires you to install the
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
               \e{Debugging tools for Windows}
               \l{http://www.microsoft.com/whdc/devtools/debugging/installx86.Mspx}{32-bit}
               or
               \l{http://www.microsoft.com/whdc/devtools/debugging/install64bit.Mspx}{64-bit}
               package (Version 6.11.1.404 for the 32-bit or the 64-bit version of Qt Creator, respectively),
               which is freely available for download from the
               \l{http://msdn.microsoft.com/en-us/default.aspx}
               {Microsoft Developer Network}.

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
               The pre-built \e{Qt SDK for Windows} makes use
               of the library if it is present on the system. When building Qt
               Creator using the Microsoft Visual C++ Compiler, the
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
               \c{"%ProgramFiles%\Debugging Tools for Windows"} path is
               checked to ensure that all required header files are there.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
       \row
           \o Debugging tools for Mac OS X
           \o The Qt binary distribution contains both debug and release
              variants of the libraries. But you have to explicitly tell the
              runtime linker that you want to use the debug libraries even if
              your application is compiled as debug as release is the default
              library.

              If you use a qmake based project in Qt Creator,  you can set a
              flag in your run configuration, in Projects mode. In the run
              configuration, select \gui{Use debug version of frameworks}.

              For more detailed information about debugging on the Mac, refer:
              \l http://developer.apple.com/mac/library/technotes/tn2004/tn2124.html

        \note The Mac OS X Snow Leopard (10.6) has a bug, that can be worked
              around as described in the link provided below:
              \l http://bugreports.qt.nokia.com/browse/QTBUG-4962.

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \section1 Interaction with the Debugger
con's avatar
con committed

    In \gui Debug mode, several dock widgets are used to interact with the
    program you are debugging. Frequently used dock widgets are visible by
    default and rarely used ones are hidden. To change the default settings,
    select \gui Debug > \gui View, and then select an option to
    lock or unlock the location of the dock widgets or display
    or hide them. The position of your dock widgets is saved for future
con's avatar
con committed
    sessions.


Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \section2 Usage of the Debugger

    To start a program under the debugger's control, select \gui{Debug} >
    \gui{Start Debugging} > \gui{Start Debugging}, or press \key{F5}.
    Qt Creator checks whether the compiled program is up-to-date, rebuilding
    it if necessary. The debugger then takes over and starts the program.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

    \note Starting a program in the debugger can take a considerable amount of
    time, typically in the range of several seconds to minutes if complex
    features (like QtWebKit) are used.

    Once the program starts running, it behaves and performs as usual.
    You can interrupt a running program by selecting \gui{Debug} >
    \gui {Interrupt}. The program is automatically interrupted as soon as a
    breakpoint is hit.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

    Once the program stops, Qt Creator:

    \list
        \o Retrieves data representing the call stack at the program's current
           position.
        \o Retrieves the contents of local variables.
        \o Examines \gui Watchers.
        \o Updates the \gui Registers, \gui Modules, and \gui Disassembler
           views.
    \endlist


    You can use the debugger views to examine the data in more detail.

    To finish debugging, press \key{Shift+F5}. You can execute a line of code
    as a whole with \key{F10}. To step into a function or a sub-function, use
    \key{F11}. You can also continue running the program with \key{F5}.

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    It is also possible to continue executing the program until the current
    function completes or jump to an arbitrary position in the current function.
con's avatar
con committed
    \section2 Breakpoints

    A breakpoint represents a position or sets of positions in the code that,
    when executed, interrupts the program being debugged and passes the control
    to you. You can then examine the state of the interrupted program, or
    continue execution either line-by-line or continuously.

    Qt Creator shows breakpoints in the \gui{Breakpoints} view which is enabled
    by default. The \gui{Breakpoints} view is also accessible when the debugger
    and the program being debugged is not running.
con's avatar
con committed

    Typically, breakpoints are associated with a source code file and line, or
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    the start of a function -- both are allowed in Qt Creator.
con's avatar
con committed

    The interruption of a program by a breakpoint can be restricted with
con's avatar
con committed
    certain conditions.

con's avatar
con committed

    \list
       \o At a particular line you want the program to stop, click the
          left margin or press \key F9 (\key F8 for Mac OS X).
       \o At a function that you want the program to interrupt, enter the
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
          function's name in \gui{Set Breakpoint at Function...} located in the
          context menu of the breakpoints view.
con's avatar
con committed
    \endlist

    \note You can remove a breakpoint:
con's avatar
con committed
    \list
        \o By clicking the breakpoint marker in the text editor.
con's avatar
con committed
        \o By selecting the breakpoint in the breakpoint view and pressing
           \key{Delete}.
        \o By selecting \gui{Delete Breakpoint} from the breakpoint's context
           menu in the \gui Breakpoints view.
    \endlist

    You can set and delete breakpoints before the program starts running or
    while it is running under the debugger's control. Breakpoints are saved
    together with a session.
con's avatar
con committed


    \section2 Stack

    When the program being debugged is interrupted, Qt Creator displays the
    nested function calls leading to the current position as a call stack
    trace. This stack trace is built up from call stack frames, each
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    representing a particular function. For each function, Qt Creator tries
    to retrieve the file name and line number of the corresponding source
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    file. This data is shown in the \gui Stack view.
con's avatar
con committed

    \image qtcreator-debug-stack.png

con's avatar
con committed
    Since the call stack leading to the current position may originate or go
    through code for which no debug information is available, not all stack
    frames have corresponding source locations. Stack frames without
    corresponding source locations are grayed out in the \gui{Stack} view.
con's avatar
con committed

    If you click a frame with a known source location, the text editor
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    jumps to the corresponding location and updates the \gui{Locals and Watchers}
    view, making it seem like the program was interrupted before entering the
    function.
con's avatar
con committed


    \section2 Threads

    If a multi-threaded program is interrupted, the \gui Thread view or the
    combobox named \gui Thread in the debugger's status bar can be used to
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    switch from one thread to another. The \gui Stack view adjusts itself
    accordingly.
con's avatar
con committed


Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \section2 Modules View and Source Files View

    The \gui{Modules} view and \gui{Source Files} view display the debugger's idea.
    By default, the \gui{Modules} view and \gui{Source Files} view are hidden.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed


    \section2 Disassembler View and Registers View

    The \gui{Disassembler} view displays disassembled code for the current
    function. The \gui{Registers} view displays the current state of the CPU's
    registers.

    The \gui{Disassembler} view and the \gui{Registers} view are both useful
    for low-level commands such as \gui{Step Single Instruction} and
    \gui{Step Over Single Instruction}. By default, both \gui{Disassembler} and
    \gui{Registers} view are hidden.
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed

con's avatar
con committed
    \section2 Locals and Watchers

    Whenever a program stops under the control of the debugger, it retrieves
    information about the topmost stack frame and displays it in the
    \gui{Locals and Watchers} view. The \gui{Locals and Watchers} view
    typically includes information about parameters of the function in that
    frame as well as the local variables.
con's avatar
con committed

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    Compound variables of struct or class type are displayed as
    "expandable" in the view. Click the "+" to expand the entry and show
    all members. Together with the display of value and type, you can
con's avatar
con committed
    examine and traverse the low-level layout of an object's data.


    \table
        \row
            \i  Gdb, and therefore Qt Creator's debugger works for optimized
                builds on Linux and Mac OS X. Optimization can lead to
                re-ordering of instructions or removal of some local variables,
                causing the \gui{Locals and Watchers} view to show unexpected
                data.
            \i  The debug information provided by gcc does not include enough
                information about the time when a variable is initialized.
                Therefore, Qt Creator can not tell whether the contents of a
                local variable contains "real data", or "initial noise". If a
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
                QObject appears uninitialized, its value is reported as
                "out of scope". Not all uninitialized objects, however, can be
con's avatar
con committed
    \endtable


    The \gui{Locals and Watchers} view also provides access to the most
    powerful feature of the debugger: comprehensive display of data belonging
    to Qt's basic objects.

    To enable Qt's basic objects data display feature:
    \list
       \o  Select \gui Tools > \gui {Options...} > \gui Debugger >
           \gui{Debugging Helper} and check the \gui{Use debugging helper}
           checkbox.
       \o  The \gui{Locals and Watchers} view is reorganized to provide a
           high-level view of the objects.
    \endlist

    For example, in case of QObject, instead of displaying a pointer to some
    private data structure, you see a list of children, signals and slots.
con's avatar
con committed

    Similarly, instead of displaying many pointers and integers, Qt Creator's
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    debugger displays the contents of a QHash or QMap in an orderly manner.
    Also, the debugger displays access data for QFileInfo and provides
    access to the "real" contents of QVariant.

    You can use the \gui{Locals and Watchers} view to change the contents of
    variables of simple data types, for example, \c int or \c float when the
    program is interrupted. To do so, click the \gui Value column, modify
    the value with the inplace editor, and press \key Enter (or \key Return).
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
    \note The set of watched items is saved in your session.
    The \l{Writing a simple program}{TextFinder} example reads a text file into
    QString and then displays it with QTextEdit.

    If you want to look at the example's QString, \c{line}, and see the
    stored data, you must place a breakpoint and view the QString object's
    data. Perform the following steps:

    \table
        \row
            \i \inlineimage qtcreator-setting-breakpoint1.png
            \i \bold{Setting a Breakpoint}

    \list 1
        \o Click in between the line number and the window border on the line
        where we invoke \l{http://doc.trolltech.com/qtextedit.html#plainText-prop}{setPlainText()}
        to set a breakpoint.
        \o Select \gui{Start Debugging} from the \gui{Debug} menu or press \key{F5}.
    \endlist

        \row
            \i \inlineimage qtcreator-setting-breakpoint2.png
            \i \bold{Viewing and removing breakpoints}

    Breakpoints are visible in the \gui{Breakpoints} view in \gui{Debug} mode.
    To remove a breakpoint, right-click it and select \gui{Delete breakpoint}.

        \row
            \i \inlineimage qtcreator-watcher.png
            \i \bold{Viewing Locals and Watchers}

    To view the contents of \c{line}, go to the \gui{Locals and
    Watchers} view.

    \endtable

    If you modify your \c{on_findButton_clicked()} function to move back to
    the start of the document and continue searching once the cursor hits the
    end of the document. You can add the restart from beginning functionality
    with the following code snippet:

    \code
    void TextFinder::on_findButton_clicked()
    {
        QString searchString = ui->lineEdit->text();

        QTextDocument *document = ui->textEdit->document();
        QTextCursor cursor = ui->textEdit->textCursor();
        cursor = document->find(searchString, cursor,
            QTextDocument::FindWholeWords);
        ui->textEdit->setTextCursor(cursor);

        bool found = cursor.isNull();

        if (!found && previouslyFound) {
            int ret = QMessageBox::question(this, tr("End of Document"),
            tr("I have reached the end of the document. Would you like "
            "me to start searching from the beginning of the document?"),
            QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

            if (ret == QMessageBox::Yes) {
                cursor = document->find(searchString,
                    QTextDocument::FindWholeWords);
                ui->textEdit->setTextCursor(cursor);