#include <QtWidgets/QApplication> #include <QtWidgets/QWidget> #include <QtWidgets/QLabel>

int main(int argc, char *argv[]) { QApplication app(argc, argv);

QWidget window;
window.setWindowTitle('Hello, World!');

QLabel *label = new QLabel('Hello, World!', &window);
label->setAlignment(Qt::AlignCenter);
label->resize(200, 50);

window.resize(300, 150);
window.show();

return app.exec();

}

此代码创建一个名为'Hello, World!'的窗口,并在窗口中显示一个标签。标签中显示'Hello, World!'文本,并居中对齐。窗口大小设置为300x150,并显示在屏幕上。

Qt 代码示例:创建简单窗口