RSS

Monthly Archives: November 2011

Build quick UI Applications using Qt Creator

Qt is widely used for developing applications with a GUI. Here I have described about a simple slider and dial desktop application. By moving the dial clockwise or anti- clockwise or by moving the slider left or right, the value on the lcd changes. So to start building the application, you need to have a Qt SDK 4.7 or higher, which you can get from here.

After you are done with the installation, click on create project and select Qt C++ Project. The Qt C++ project has three options, from that select the first one, Qt Gui Application.

Give a name to your project and select the Desktop Qt version.

Go to the next step and click on finish project.The IDE will show your project with some files, which are automatically generated by Qt, in the project explorer. These files are .pro, .cpp, .ui, .h.

Click on the mainwindow.ui, and drag and drop the components which you want to include in the ui. In this example, I have used a dial, a  horizontal slider and a LCD number. Finally the ui would appear like this.

Now we have to assign signals and slots, since we want to notify the lcd to increment or decrement the number while the dial or the slider is moved. So right click on the dial and click on ‘Go to slot’. There will be several options available, select the ‘ value(changed) ‘ option. Repeat the same step with right clicking on the horizontal slider.

After doing the above step, the mainwindow.cpp and mainwindow.h file will automatically create these two methods and their declarations in the header file.

To add the functionality to the dial and slider, just add the line

ui->lcdnumber->display(value);

in both the methods. Do not forget to save the project side by side while making the changes.Click on the window property editor, from where you can set the dial’s min, max value, step change etc. In this example I have set the min value as 0 and max as 99. The step size is 1. The max no. of digits which can be displayed on lcd can also be set from here itself.

Now click on the run button, the application will start and certain output messages will come in the console window. You will see the application running on the system ;) . In this way you can create quick user interface apps using the Qt SDK.

 
1 Comment

Posted by on November 23, 2011 in Embedded, GUI Application, Qt

 
 
Follow

Get every new post delivered to your Inbox.