Jump to content

Qt/Lesson 1

From Wikibooks, open books for an open world
< Qt

Hello, World!

[edit | edit source]

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

#include <QApplication>
#include <QLabel>

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

To compile this, read Development Environment or just use g++ `pkg-config --libs --cflags Qt5Core Qt5Widgets` main.cpp.

Using Qt designer

[edit | edit source]

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.