Skip to content
Andy Simmonett edited this page Jan 9, 2017 · 1 revision

Qt Creator

Using Qt Creator for Psi Development

Because of the complexity of Psi, it can be quite laborious to use vi for development. A lot of IDEs exist for this purpose, but most are written in Java and have a huge computational overhead associated with them. A very good solution is to use Qt Creator , which can be downloaded as a binary from ​here , or compiled from ​source . Because Qt programs are written in C++ and compiled into native applications, they don't have the overhead of running through an interpreter. NetBeans is one of the best Java-based solutions around, but struggles to parse the Boost headers in Psi because of the sheer number of them, so we'll focus on the Qt Creator approach here as it uses very little CPU and greatly reduces the effort of development. Like the Java-based solutions, Creator is available on all platforms.

Getting Started

Since Creator detects SVN or Git repositories automatically, it's a good idea to set up your Git repository from the command line before proceeding if you plan to use Git versioning. The following instructions are for an existing Psi installation with either Git or SVN repository handling.

  • Select "File" -> "New File or Project...".
  • Select "Other Project" -> "Import Existing Project", click "Choose...".
  • Enter "Psi4" as the project name, and point the location to the Psi4 top directory, click "Continue".
  • In the "Add to Version Control" window, select "none" so that the files generated by Creator are not checked in to the repository.

To have Creator check out from SVN instead of using existing sources, the second step of the above procedure should be "Project from Version Control" -> "Subversion Checkout"

Setting Build Rules

The most useful thing about IDEs is the ability to create custom procedures for building code. Building the entire Psi code every time a change is very inconvenient because of the amount of time it takes. For this reason, you should consider using plugins for new codes. You can make multiple rules for building Psi, which will be appropriate for different lines of development. For example, if you want a rule that builds all of Psi, you can do the following

  • Click "Projects" on the left hand side of the screen.
  • In "Build Settings", Choose "Add" -> "Build" and enter "all" as the name.
  • Set the "Build Directory" to the Psi build directory.
  • The defaults are reasonable, but you can add "-j 4" to the "Make Arguments", under the "Details" tab of the "Build Steps" section, to compile on 4 CPUs.

Now you can select "all" from the pulldown after clicking the computer icon in the bottom left of the pane in the main window, to activate this configuration. Hitting "Cmd + B" ("Ctrl + B" on non-Macs) or clicking the hammer in the bottom left of the screen will build all of the Psi code. If we're developing, say the scf code, it doesn't make sense to recompile the entire distribution. Instead, we can make another rule:

  • Click "Projects" on the left hand side of the screen.
  • In "Build Settings", select the "all" configuration, and click "Add" ->"Clone Selected", and name this one "scf only".
  • Set the "Build Directory" to "(path to psi4 build directory)/src/bin/scf", and add any arguments to make, as described above.
  • After recompiling the scf library, we need to link it into the main executable, so we can click "Add Build Step" -> "Custom Process Step".
  • In the newly-created step, enter "/usr/bin/make" in the "Command" box and "(path to psi4 build directory)/src/bin/psi4" as the "Working directory".

Now, selecting the "scf" target will cause only the scf module be recompiled and linked.

Debugging

Creator has a very powerful debugger built in, which is easy to to set up and use. First, rules for running executables have to be set up:

  • Click "Projects" on the left hand side of the screen.
  • In "Run Settings", enter a name in the "Name" box, or click "Add" to add a new configuration
  • Enter "(path to psi4 build directory)/bin/psi4" in the "Executable" box, and enter the path to the input file in the "Working directory" box.

Now you can just click the "Debug" symbol in the left pane, then the small, green "start" button to debug. The stack is shown on the left, along with values of all variables for each entry in the stack. Breakpoints can be inserted into the code by opening the appropriate file and clicking the empty column to the left of the line number on the line where you want to insert the breakpoint; clicking the red blob that appears will remove the breakpoint.

Useful Tips

  • You can hold "Cmd" ("Ctrl" on non-Macs) and hover over any function/variable to turn it into a link that, when clicked, takes you to the definition and declaration.
  • You can hold "Cmd" ("Ctrl" on non-Macs) and hover over any included file name to open that file.
  • Right-clicking a variable name and selecting "Find usages" will show all the places where that variable is used.
  • Right-clicking a variable name and selecting "Rename Symbol Under Cursor" will rename all instances of that variable.
  • "Cmd + 0" will toggle the file browser view.
  • "Cmd + 1", "Cmd + 2", "Cmd + 3", or "Cmd + 4" can be used to show/collapse the Build problems/Search Results/Application Output/Compilation Output panes, respectively.
  • "Cmd + /" will comment / uncomment selected lines.
  • "Cmd + `" will switch between declarations and definitions.
  • Selecting multiple lines and hitting tab will indent them all, "shift + tab" will unindent.
  • To obtain nice colored-coded code for python, download a version of Qt Creator >= 2.1. In Preferences, select the Generic Highlighter tab from the Text Editor side panel and then choose Python, Perl, etc. at the Download Definitions button.

The Projects View

The "Projects" bar on the left doesn't update itself as new files are added and removed. Only the files that are present in the Project view are parsed during refactoring and search/replacing. If files and/or folders have been added since the Creator project was set up, they don't automatically show up in the Projects view, which is really annoying. One way to sort this out is to add the missing files by right clicking the appropriate folder in the Projects view, and using the "Add Existing Files..." option to tell Creator about them. The easier approach is to just go to File->"New File or Project..." and create a "new" project in the same location, with the same name as the existing one. When Creator asks you if you want to overwrite the existing setup files, say yes (and tell it not to add any file to version control, just as you did when setting up the project before). You must close the project before re-initializing it, but it's really quick to do (only 2 menus to navigate). Overwriting the setup files does not destroy any existing build rules.

If you're using git to manage your repository there is another way to update your Projects view. First, close your project in Creator. From the command line in the directory of your Psi4 project file type::

git ls-files > 'project'.files

where 'project' is the name of your Project in Creator. For instance, if I named my project Psi4 in Creator the file would be Psi4.files.

Setting up the Help Menu

A very nice feature of Qt Creator is the ability to import Psi4's Doxygen generated help. Qt Creator has the ability to provide context sensitive help to you on all of Psi4's functions. For instance, if you can't remember all the parameters needed to call C_DGEMM all you have to do is hover your mouse over the function and press F1.

To set this up you first need to generate the Doxygen help. It might take a few minutes to do this. ::

cd $(objdir)/doc/doxygen
make

If you have Qt installed on your system and the configure script was able to find the qhelpgenerator program you should see at the end of the make command::

Running qhelpgenerator...
Building up file structure...
Insert custom filters...
Insert help data for filter section (1 of 1)...
Insert files...
Insert contents...
Insert indices...
Documentation successfully generated.

If you do not see this skip down below.

Next, in Qt Creator open the Preferences window, click Help on the left, then click the Documentation tab in the middle. Next, click Add... and navigate to $(objdir)/doc/doxygen/qch. You should see PSI-4.0.0-alpha.qch, click it and click OK. Psi4's help documentation is now available in Qt Creator.

If you didn't see the above text...

Make sure you have Qt installed and that you can locate qhelpgenerator. Once found type in the $(objdri)/doc/doxygen directory::

qhelpgenerator index.qhp -o psi4.qch

Then in Qt Creator open the Preferences window, click Help on the left, then click the Documentation tab in the middle. Next, click Add... and navigate to $(objdir)/doc/doxygen. You should see psi4.qch, click it and click OK. Psi4's help documentation is now available in Qt Creator