Archived:How to create your first Qt application
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated. Note that this has the ArticleNeedsUpdate template. If the article is migrated to Qt Quick then it can be de-archived.
This article explains the basic steps to create a simple application using Qt. This article mainly aims at beginners and helps them create their very first application.
Article Metadata
Reasons: hamishwillee (26 Aug 2011)
There are other articles on getting started with Qt. I think that we should ensure that there isn't more than one unless they provide a significantly different and valid approaches. So proposal is a review of articles on this topic on this wiki and merging where necessary. There should also be an update of links to the guidance in the library to point to other options like using Qt Quick and the Qt Components libraries for different platforms.
Whatever happens, it is also clear that this is out of date
- Uses Qt Creator 1.3 - we're up to 2.x
- Suggests Qt widgets, while most development would be best using Qt Quick for the UI
(Note that this article also explains the initial steps, that is, installation steps before developing any Qt application.)
Contents |
Introduction
Qt (pronounced "cute") is a cross-platform development and application framework. The programming language used in Qt is C++. So if you have basic knowledge of C++ you can start developing applications with Qt. And if you don't have the knowledge of Qt, you can learn C++ from the site given in the Reference section.
Applications made with Qt can be made to run on a desktop as well as on a mobile without modifying the source code, as it is a cross-platform application framework. Thus Qt provides flexibility and ease to the developer with a great efficiency in the application. There are also many more advantages of using Qt. To get more details, please visit A tour to the Qt (Qt).
Installation
If you want to develop applications with Qt, you need to download the Qt SDK for Windows. You can download it from Download Qt, the cross-platform application framework.
(Go to LGPL and download the Qt SDK as per your need. SDKs also includes the Qt Creator which is the IDE for developing applications with Qt.)
You can also visit Archived:Qt Tutorial Lesson 1 - Installation to get more detailed information about the installations.
Steps to Create a Qt GUI Application
- After installing the Qt SDK, Open your Qt Creator 1.3 IDE.
- Click on File -> New File or Project...
- Choose Qt4 Gui Application.
- Give a name to your application and then press Next.
- Now press Next
- Press Next
- Press Finish.
Your application will have these much of folders and files:
- Hello_Deepika.pro
- mainwindow.ui
- mainwindow.h
- main.cpp
- mainwindow.cpp
- Hello_Deepika.pro is your project file. It keeps the information about your application.
- mainwindow.ui is the file where your user interface (or you can say view) of your application will be created. Just click on this file, you will get the window of your application, here you can place the components from the list given on the left side of your IDE.
Here I have chosen a press button from the button's list and placed it on the application's window (though I have not handled the event generated by pressing the button yet...). This concept follows the "Signal and Slot" mechanism. You can refer to signal and slot related articles for the same in Signals and Slots, How to use Signals and Slot in Qt. You can do it in the .cpp file according to your logic.)
You can also read Creating a signal to slot connection in Qt Designer for a better understanding of signal and slot in Qt with images.
- Now compile your application from the options given in the downside of the Qt Creator.
- Build the application by right clicking on the application's name and then run it by doing the same.
- You will get the output as shown in the figure below.
That's it! You have created you first Qt application successfully!
References:
- You can learn C++ at :











Needed?
Don't we have enough articles of that kind? --axeljaeger 14:47, 6 April 2010 (UTC)
Hamishwillee - What about Qt Quick?
I'm not going to argue whether we need this article or not. However it is clear that the first Qt application now days should probably be in Qt quick. Arguably it should also use the Qt Quick Components. It certainly should use latest Qt creator. I'll add "ArticleNeedsUpdate"hamishwillee 09:46, 26 August 2011 (EEST)