Saturday, October 20, 2012

Running in QtCreator

After the program has been built it can be run or debugged in QtCreator.  For now, command line arguments need to be added before running the program, otherwise it will only output a usage message.

Command line arguments are set on the Projects screen (the Projects icon on the side or Ctrl+5) by selecting the Run Settings button along the top of the screen.  For example, under Run, enter ../thunder422‑ibcp/test/translator01.dat to run the first translator test (assuming the default directories were used up to now).

Again there are multiple ways to run the program (play icon on lower side, Ctrl+R, Run on the Build menu).  Same for running in the debugger; though note that in order to trace through the program, a breakpoint needs to be set first or the program runs (in the debugger) until it exits.

Building With QtCreator

Now that it has been configured for all the tools, everything can be done inside QtCreator.  Start QtCreator and select New Project... on the File menu.  In the New dialog select Project from Version Control and then Git Repository Clone.  After clicking the Choose... button, the git repository can be selected.  For Clone URL: enter https://github.com/thunder422/ibcp.  If desired, change the Checkout path.  The Checkout directory will default to thunder422-ibcp.  Click the Next button and the repository will be cloned.

Once finished, the CMake Wizard dialog appears asking for the Build Location.  The default directory can be used.  The next dialog of the wizard is to Run CMake.  On Windows, the Generator: needs to be changed to MinGW Generator (MinGW (x86 32bit)) assuming MinGW 4.4 was installed with Qt SDK, otherwise this is the only generator available.

Clicking the Run CMake button at this point causes a bunch of errors.  Adding ‑G "MSYS Makefiles" to the Arguments: line appears to resolve the problem.  Adding this before clicking the Run CMake button the first time does not make it work though clicking a second time does.  Clicking the Run CMake button a second time works.  I have no explanation for this at the moment.  This is a similar problem that caused issues with NetBeans and CMake.  On Linux, clicking the Run CMake button is all that is necessary.

Adding ‑DCMAKE_BUILD_TYPE=Debug to the Arguments: line turns on debug information to that the debugger can be used. After CMake is run, the program can be built.  There are a number of ways to begin the build, including the Build menu, Ctrl+B and the hammer looking icon at the bottom of the tool bar on the left side.  The build can be monitored by clicking the 4 Compile Output button along the bottom of the screen.

Post Qt Installation Setup (Windows)

After installation of the Qt SDK, the tools (git, MinGW and CMake) need to be integrated with QtCreator.  On Linux, no further configuration is needed as all tools will be located where QtCreator can find them.  However, on Windows, this is not the case.

For git, the binary directory for the git tools need to be in the execution path.  On Windows XP, right-click on My Computer and select Properties.  On the Advanced tab, click the Environment Variables button.  On the lower pane under System Variables, find and selected the Path variable.  Click Edit and add C:\Program Files\Git\bin somewhere on the Variable value line (make sure to add the semicolon separator).  On Windows 7 the instructions are similar.  Start by right-clicking Computer and select Properties.  Now select Advanced system settings, go to the Advanced tab and follow the same instructions except add C:\Program Files (x86)\Git\bin to Path.

Now start QtCreatorQtCreator should have automatically found the external MSYS/MinGW 4.6.2 previously installed.  On the Tools menu select Options, go to the Build & Run page, and select the Tool Chains tab.  Under Auto-detected there will be an entry Mingw as a GCC for Windows targets (if the MinGW 4.4 was installed as part of Qt SDK) and an entry MinGW (x86 32bit), which is the previously installed MinGW 4.6.2.  The g++ path can be seen by selecting this entry, which should show C:\MinGW\bin\g++.exe.

For the final tool, CMake, select the CMake tab next to Tool Chains.  If the correct path was added to the Path under Environment Variables, the path to cmake.exe will already be set.  Otherwise, click Browse and find cmake.exe, which will be found under C:\Program Files\CMake 2.8\bin\cmake.exe (Windows XP) or
C:\Program Files (x86)\CMake 2.8\bin\cmake.exe (Windows 7) if CMake was installed in the default location.  Don't select cmake-gui.exe.

Now it's time to see if QtCreator is able to build and debug the ibcp program before we start any Qt related modifications.

Installation For Qt Development

On Windows, when installing the Qt SDK, select Custom then on the Select Components dialog, unselect the following under Documentation: Harmattan, Qt Simulator, Symbian, and Qt Mobility; under APIs: Qt Mobility APIs and Qt Quick Components for Symbian; and under Development Tools: Harmattan, Simulator, Symbian Toolchains, under Desktop Qt: Qt 4.7.4 (Qt 4.8.1 will be used).  Under Miscellaneous, it is unnecessary to select MinGW 4.4 (the previously installed MSYS/MinGW 4.6.2 will be used, see here for instructions).  Also, the Qt Examples are not necessary but can be left in.

These selections will decrease the amount to download when using the on-line installer.  Once installed, any of the unselected components can be added using the Maintain Qt SDK program under the Qt SDK program group using the Package manager.  The Default installation can also be used  Once installed, QtCreator needs to be connected to our tools (git, MinGW and CMake; see next post).

On Linux, the download installers can be used with the same selections as above (make sure the correct installer versions are downloaded, 32-bit or 64-bit to match the version of Linux).  On Ubuntu 12.04 based distros (for example Linux Mint 13), it is not necessary to install the Qt SDK as the packages needed for Qt development are in the Ubuntu repositories.  Most of the Qt libraries should already be installed (especially if KDE is being used since it was developed using Qt).  The only additional packages that need to be installed are qtcreator, libqt4‑dev, qtcreator‑doc and qt4‑doc (use the sudo apt‑get install command or the package manager).  The version of QtCreator installed from the repositories is the same as in the current Qt SDK, specifically 2.4.1.

Preparing For Qt Development

Qt has its own IDE (Integrated Development Environment) called QtCreator.  Qt also requires all the various Qt libraries as well as Qt header files and several utilities.  Qt has its own make system called Qmake, but QtCreator is also compatible with CMake, so Qmake won't be used.

For Windows, the best way to start is to simply install the Qt SDK (Software Development Kit) that contains and installs all the necessary programs and files.  The current SDK, version 1.2.1, which contains Qt libraries version 4.8.1 and QtCreator version 2.4.1 as well as MinGW compiler suite.  However, the version of MinGW installed contains an older GCC, version 4.4.  Although it can easily be made to work with an existing MSYS/MinGW installation like the one the project has been using based on GCC 4.6.2.

Several choices of installers are available, a small on-line installer and a very large off-line installer.  The off-line installer has the advantage of quick reinstalls.  However, the on-line installer only downloads the components selected during installation so potentially there is much less to download (more can be downloaded and installed later if needed).  Many of the components are unnecessary when strictly used for desktop development (for example, all the mobile development files can be ignored).  Next post, installation...

New Focus – Introducing Qt

When this project was started, the plan was to first develop all the internal routines (parser, translator, recreator, etc) and wrap a simple command line interface around it initially for testing before tackling a modern interface (GUI).  I even went as far as starting to learn about using the Console mode on Windows (though this couldn't be used on Linux).  That was the purpose in parsing immediate commands.

Over the past year or so, I have been learning and using Qt, a cross-platform application framework (and it is Open Source).  With Qt, it is fairly easy to develop programs with a sophisticated GUI, plus it does a whole lot more.  So instead of fooling with some antiquated command line interface, the project will be transitioned over to using Qt.  This desire accelerated after discovering the Basic-256 program early this year.  This program is a great platform for teaching programming (was formally called Kid-Basic).  This program also uses Qt.

It is not totally clear all what is necessary for this transition to Qt, but several items come to mind.  The classes implemented towards the beginning of the project, the List and Stack classes, will be removed and the Qt equivalents will used in their place.  Though not necessary, variable and function names will be changed to the Qt way of naming.  The exceptions used during initialization will be removed as there are no exceptions in Qt.

Since this will be a major change in development, the Release 0.1 series will be concluded and development of the Release 0.2 series will begin.  The change in direction mentioned with Release 0.1.15 will continue after the transition to Qt.  First though, the computer needs to set up for Qt Development...