Qt/Lesson 1

From Wikibooks, open books for an open world
< Qt
Jump to: navigation, search

[edit] Hello, World!

This is the Hello, World! program. It just displays a window:

#include <QtGui>
 
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel label("Hello, world!");
    label.show();
    return app.exec();
}

[edit] Compiling and executing Qt hello world program

1. Create a folder named Hello
2. Copy paste the above program as Hello.cpp in folder Hello
3. At Hello folder run

 a. qmake -project
 b. qmake 
 c. make/gmake/nmake - as needed by OS and your compiler setups

4. Execute ./release/Hello (Or release\Hello.exe in Windows)

[edit] Using Qt designer

This lesson will get you started using Qt designer for making your own simple application.

Open Qt Designer and select to make a new dialog without buttons. Drag a label on to it and set its title property to "Hello, World!", then go to Form > Preview to see your new dialog. Now, onto writing some code. We'll have to subclass the QDialog class to make the application run standalone on most modern operating systems.

    • screenshots and more coming soon**
Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
In other languages
Sister projects
Print/export