HowTo Use OpenFOAM with QtCreator
Qt Creator is a powerful and flexible cross-platform integrated development environment (IDE) with strong orientation and support for C/C++ native development.
Contents
1 Why to use Qt Creator?
- Open Source
- Cross Platform – Works perfectly on Linux, Windows and Mac OS X
- Direct compatibility with other applications of Qt SDK (great for building GUI-applications!)
- Actively developed and improved
- Excellent syntax highlighting
- Magnificent code browsing and navigation in combination with useful and customizable keyboard shortcuts
- Great and generic (works with any file you include, it doesn’t have to know anything special about it)
- Code completion support
- Easily customizable and Extensible through plugins
- Support for integration with various Source Control Management tools like Git, Subversion, Bazaar, Mercurial, CVS and more.
- Debugger integration with both GDB and Microsoft’s Debugging Tools for Windows through CDB
- Custom configure, build, clean and deployment steps
- Integration with tools like Valgrind
- Per project settings
- Vim editing mode
- Code snippets
- A pretty fast IDE, even when indexing hundreds of files with hundreds of thousands lines of code for the first time
- Linux Man Pages context help integration - thanks to the flexible Qt Help System, this can be extended to almost any API
2 Download and installation
Most of the main Linux distributions have binaries in their repositories. Otherwise, download and install Qt Creator from http://qt.nokia.com/downloads.
Installation example in Debian/Ubuntu:
# apt-get install qtcreator
3 OpenFOAM project in Qt Creator
Obs.: Using Qt Creator version 2.5.0
3.1 Starting a project
- Open Qt Creator.
- Go to File New File or Project Other Project.
- Click on Import Existing Project.
- Give your project a name and select the location to your project source tree. Select the directory where the source-files (*.C, *.H) of your OpenFOAM application are. A project-file <project name>.creator will be created inside the selected directory.
- A screen will pop up asking you to select the files to be added to the project.
- The next screen, Project Management, is going to ask you if you want to use source control management (git, svn) for your project and if yes,then the project files will be the first to be added to the project. You should add these files to the scm repository only if you know that they would be usefull for others, otherwise you should keep them to your self, by using exclude directives like .gitignore files in git or svn:ignoreproperty in svn.
If everything went well, your project is ready.
3.2 Configuring for wmake
You should now have your project open in Qt Creator and ready to proceed to project settings. On the left side of Qt Creator click on Projects. Right now you’re looking at the Build Settings screen. This is where you set your project building and cleaning steps.
- Build directory is your reference directory stored in %{buildDir} variable.
You have probably configured your OpenFOAM to work in the shell terminal by adding the command
source /usr/local/OpenFOAM/OpenFOAM-2.1.0/etc/bashrc
to your ~/.bashrc script-file. This exports environment variables pointing to libraries and executables directories of a selected OpenFOAM version. However, ~/.bashrc-script will not be able run if you launch Qt Creator from the window manager and you will not be able to simply call wmake to compile your application. Yet, there are several ways to use wmake.
3.2.1 Option 1: using foamExec
The cleanest in my opinion. Run the command foamExec with command argument wmake or wclean, as shown in the Figure above. This foamExec-script will load any OpenFOAM application of its same version (in this case 2.1.0).
3.2.2 Option 2: write your own script
Other less advisable option is to write your own shell script like the makeScript also shown in the same Figure. Notice that this option was disabled there, so only the first is run by the Build Project command.
#!/bin/bash #Adding OpenFoam to shell environment source /usr/local/OpenFOAM/OpenFOAM-2.1.0/etc/bashrc if [ "$1" = clean ]; then echo wmake\: cleaning... wclean exit else if [ "$1" = build ]; then echo wmake\: building... wmake exit else echo $0\: \*\*\* No rule to $0 target \'$1\'. Stop. exit fi fi
3.2.3 Option 3: Add environment variables manually
well... more work... You can call wmake and wclean from OpenFOAM's bin directory.
4 References
This tutorial is based on: