From The Mana World
Revision as of 19:42, 1 July 2013 by Jaxad0127 (talk | contribs) (Jaxad0127 moved page Developing with Qt Creator to Archive:Developing with Qt Creator without leaving a redirect)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The upcoming Qt Creator 1.1 will have a generic project manager intended to support any existing build system. Using this project manager, you just tell Qt Creator which files are part of your project and which compiler defines and include paths to use. This means you can use Qt Creator to develop The Mana World. Here is how. :-)

Note: Since Qt Creator will simply run 'make' for you on build, you'll need to have your environment and compiler already set up for compiling The Mana World!

Warning: Only tested on Linux so far!

Disclaimer: I am one of the developers of Qt Creator, so I hope this article won't be seen too much as advertisement. Of course I'm curious about your feedback, but the main reason this article is here is really just cause I think Qt Creator is a really nice IDE, and I have personally always looked forward to being able to use it for TMW development.

Downloading Qt Creator

Since we'll be relying on a feature in the next release, you have to either check Qt Creator out from the git repository (1.1 branch) or get the 1.1.0-rc1 release from here:

ftp://ftp.qtsoftware.com/qtcreator/

Daily snapshots are also available, though at the moment just for Linux. Installing should be pretty straight-forward.

Importing The Mana World project

Start Qt Creator and go to File -> New..., and then choose Import of Makefile-based Project. Enter the project name and the specify the location. On the next page, it will show you which files will be generated. These will be the following, depending on what you chose as project name:

.../tmw.files          # List all the files that are part of the project (for code navigation)
.../tmw.includes       # Lists include paths (by default all directories with header files)
.../tmw.config         # Here you add defines
.../tmw.creator        # This is the actual project file you use to open this project

Finish the new project wizard, the new project will be automatically opened.

Specifying the include paths

Open tmw.files. On Linux, remove all include paths Qt Creator added by default (we don't use local include paths currently for TMW). On Windows, when you extracted the DevPack to your project directory, leave the 'include' entry there. In addition, specify whatever other path you need.

On Linux the file should usually contain:

/usr/include
/usr/include/SDL
/usr/include/libxml2

Specifying the defines

Open tmw.config. There's one important define, which is USE_OPENGL, to enable OpenGL support. Another is ENABLE_NLS to enable internationalization. Both are part of config.h on Linux, so on Linux you only need to specify HAVE_CONFIG_H.

Example for Linux:

// ADD PREDEFINED MACROS HERE!
#define HAVE_CONFIG_H 1

Example for Windows:

// ADD PREDEFINED MACROS HERE!
#define USE_OPENGL 1
#define ENABLE_NLS 1

Specifying additional files

By default, Qt Creator adds any files that it recognizes. At the moment this doesn't include for example Makefile.am file. You can just add those to the list in tmw.files. For now the only way to keep your file list up to date is manually.

Creating a Run Configuration

Qt Creator can't automatically determine which executable it should run. Hence, set up a custom executable run configuration in the Projects mode, at the Run Settings tab (use the + button). Specify the name, executable, optionally some arguments. The working directory is $BUILDDIR by default, which should generally work fine.

An Introduction to Qt Creator

I might as well just point you to A Quick Tour of Qt Creator, however I will note a few things that in my opinion make Qt Creator very interesting for C++ development.

Navigation

You can jump to the definition of any symbol under your cursor using F2, and switch between declaration and definition of a method using Shift+F2. Switch between source and header file using F4. Open any file in the project quickly by using Ctrl+K and just start typing the file name. You can also jump quickly to classes or methods by pressing c or m respectively, followed by a space, after Ctrl+K. Jump to line is under Ctrl+L. Going back/forward in history is Alt+Right and Alt+Left, while switching editors is under Ctrl+Tab.

Ctrl+F triggers an incremental find in the current editor, while Ctrl+Shift+F searches all the files in the project.

Code completion

Qt Creator will complete automatically whenever you type a dot, arrow, double-colon or start a Doxygen command. You can manually activate the completion using Ctrl+Space.

A nice aspect of the completion is that it's camel-case aware. If you want to complete "clearLocally" on a ParticleList instance, you only need to type "cL" and press enter. Qt Creator is also smart enough to know when a dot isn't possible, and will automatically replace it with an arrow in that case.

Build and Run

To build the project, press Ctrl+B. To build and then run, press Ctrl+R.