Application Development in Qt

In Qt, basically 5 types of applications can be developed. Depending on your purpose, you choose the one and all the environment for developing the application is provided by the framework. They are namely:

  • Qt Widgets Application
  • <li>Qt Quick Application</li>
    <li>Qt Quick UI Application</li>
    <li>HTML5 Application</li>
    <li>Qt Console Application</li>

In this post, I will be telling you about the first three.

Qt Widgets Application
Widgets form the basic building up entity of a user interface application. Talking in context to any CAD software’s UI, you see a button, a menubar, anything on the user interface, that is a widget. You are able to access the functionalities, the services provided by the software by means of these. These all are widgets.

When you choose to develop this type of application, whatever you do is in C++. This is what the framework provides by default. The thing would be different if you add some QML files in the resources folder of the app. Will be telling you about QML ahead. In this app, we have a UI file by default which is created in design mode of QtCreator. UI files are centred to widget based approach only.

Huh, now coming to the two modes of QtCreator. They are: edit mode and design mode. In edit mode, you do the coding part while in design mode, you have the actual look of the window. You can select any component say a toolbutton or any other component and place it on the window at the place where you want. The associated functionality of the component added in design mode is implemented by means of slots. Well, that is a different concept. Signal-slot mechanism is the soul behind the working of UI apps in Qt. Will be telling some other time.

Just manipulate the code in edit mode and see the components you added in action.

Qt Quick UI Application
This application is developed using the QML(acronym for Qt Modeling Language). It is Javascript based language and centred mainly for user interfaces’ applications. In this type of application, only QML is in action. QML is part of Qt Quick which is a UI-creation kit. You can work in edit mode or design mode here also. Well, working in design mode makes things so easy. The functioning is added in edit mode just like QtWidgets application.

Qt Quick Application
This application is a combination of the previous two. You can have C++ and QML both working in the same project. The rest things are the same as the previous two types of applications.

Well, this was all for someone entirely dummy in application development in Qt, covering some simple things yet important.

Compiling OGRE app in QtCreator

OGRE applications can be built in various IDEs. I went on with my friend these days- QtCreator. In order to be able to see OGRE working on my system, I made an application with pre-constructed code. You can follow the instructions below:

  1. Just download the file at this link and un-tar it. This download contains a tutorial, a dist directory and a cmake script.
  2. Put the files in a directory, say ogre-demo.
  3. Now open QtCreator and open the CMakeLists.txt file here.
  4. A dialog box will ask you to choose a build directory. By default, a new build directory is created. Just click next.
  5. Now, you will be asked to run cmake. Click the “Run Cmake” button.
  6. After this, open terminal and move to the build directory.
  7. Run make && make install there. If you do not run these, the console below in QtCreator would display an exit message.
  8. Now, you can run the app in QtCreator. You will be having a blank black screen in front of you just like the one below, though the app has compiled and is running decently.

screenshot06282014_175534208

Time to add something to see OGRE in action. 😀 I told about tutorial framework in the download done in step 1. Remember? Hm! Counting on the files in it, the entity that would be displayed in the OGRE window on running the app is defined in the file TutorialApplication.cpp. Open the file and you will find the function createScene() is empty.

Make your function look like:

void TutorialApplication::createScene(void)
{
// Set the scene's ambient light
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));

    // Create an Entity
    Ogre::Entity* ogreHead = mSceneMgr-&gt;createEntity("Head", "ogrehead.mesh");

    // Create a SceneNode and attach the Entity to it
    Ogre::SceneNode* headNode = mSceneMgr-&gt;getRootSceneNode()-&gt;createChildSceneNode("HeadNode");
    headNode-&gt;attachObject(ogreHead);

    // Create a Light and set its position
    Ogre::Light* light = mSceneMgr-&gt;createLight("MainLight");
    light-&gt;setPosition(20.0f, 80.0f, 50.0f);

}

Scrutinizing the code above, you will find entity Head whose source file is ogrehead.mesh. This file is present in the dist folder we got during the download, more specifically in dist/media/models folder.

Save your file and run the app. And you get this output:


screenshot06282014_181505778

Once the program is working, use the WASD keys to move, and the mouse to look around. The Escape key exits the program.

You got a basic OGRE app working with QtCreator on your system.

Well, I did not go with literal meaning of OGRE this time. 😛 You know what it is? The word "ogre" is of French origin and is used to depict a large, hideous, manlike monster that eats human beings. Ogres frequently feature in mythology, folklore, and fiction throughout the world. The above output illustrates it well! 😀