Difference between revisions of "Qt (简体中文)"

From ArchWiki
Jump to: navigation, search
(use https for links to archlinux.org)
(update translation)
Line 3: Line 3:
 
[[Category:简体中文]]
 
[[Category:简体中文]]
 
[[en:Qt]]
 
[[en:Qt]]
 +
[[es:Qt]]
 
{{Article summary start|摘要}}
 
{{Article summary start|摘要}}
{{Article summary text|本文包含了 Qt 的安装和使用。}}
+
{{Article summary text|Qt 为使用 C++ 或者 QML(一种类似于 CSS & JavaScript 的语言)的开发者提供一个跨平台的应用和用户界面框架。本文涵盖了 Qt 的安装和使用,以及配置主题、字体和其它选项的工具。}}
 
{{Article summary heading|相关}}
 
{{Article summary heading|相关}}
 +
{{Article summary wiki|KDE (简体中文)}}
 
{{Article summary wiki|Uniform Look for QT and GTK Applications (简体中文)}}
 
{{Article summary wiki|Uniform Look for QT and GTK Applications (简体中文)}}
 
{{Article summary wiki|GTK+ (简体中文)}}
 
{{Article summary wiki|GTK+ (简体中文)}}
{{Article summary wiki|KDE (简体中文)}}
 
 
{{Article summary end}}
 
{{Article summary end}}
{{TranslationStatus (简体中文)|Qt|2012-09-27|216870}}
+
{{translateme}}
"[http://qt.nokia.com/products Qt] 是一个跨平台的应用程序和 UI 框架,提供了C++编程的 API 和 Qt Quick 来完成快速的 UI 设计。
+
{{TranslationStatus (简体中文)|Qt|2013-03-23|249332}}
 +
 
 +
[http://qt-project.org/ Qt] 是一个跨平台的应用程序和组件工具,它使用标准 C++,并大量地将特殊的代码生成器(称为 [http://qt-project.org/doc/qt-4.8/moc.html Meta Object Compiler],或者 moc)和数个宏并用来增强语言。它的一些重要特征包括:
 +
 
 +
* Running on the major desktop platforms and some of the mobile platforms.
 +
* Extensive internationalization support.
 +
* A complete library that provides SQL database access, XML parsing, thread management, network support, and a unified cross-platform application programming interface (API) for file handling.
 +
 
 +
Qt 框架正在成为主要的开发平台,同时是 [[KDE]] 软件社区的基础, among other important open source and proprietary applications such as [[VLC]], [[VirtualBox]], [[Opera]], [[Mathematica]], [[Skype]], [[Maya]] and many others.
 +
 
 +
== 安装 ==
 +
 
 +
[[official repositories|官方源]]中现有三个版本的 Qt,能用以下软件包来[[Pacman|安装]]:
 +
* '''Qt 5.x''' is available in the {{Pkg|qt5-base}} package, with documentation in the {{Pkg|qt5-doc}} package.
 +
* '''Qt 4.x''' is available in the {{Pkg|qt4}} package.
 +
* '''Qt 3.x''' is availalbe in the {{Pkg|qt3}} package, with documentation in the {{Pkg|qt3-doc}} package.
 +
 
 +
{{Note|Qt3 is no longer developed, but there are still applications in the official repositories that depend on it. The [[Trinity]] Project is maintaining a version of Qt3 in the form of the {{Pkg|trinity-qt3}} package, available in the [[AUR]].}}
 +
 
 +
{{Warning|Installing Qt5 affects the Qt4 environment because its binaries are in /usr/bin/. This may cause compilation failures in Qt4 applications.}}
 +
 
 +
{{警告|安装 Qt3 会影响 Qt4 环境,因为它[https://projects.archlinux.org/svntogit/packages.git/tree/trunk/qt.profile?h=packages/qt3 改变了某些 Qt 环境变量]。这可能导致 Qt4 应用程序编译失败。}}
 +
 
 +
== 外观 ==
 +
 
 +
=== 配置 ===
 +
 
 +
Qt application will try to mimic the behavior of the desktop environment they are running on, unless they run into some problems or hard-coded settings. For those who still want to change the look and feel of Qt application, the ''Qt Configuration'' ({{ic|qtconfig}} or {{ic|qt3config}}) tool is available. ''QtConfig'' offers a very simple configuration for the appearance of Qt applications that gives the user easy access to the current Qt Style, colors, fonts and other more advanced options.
 +
 
 +
Although not part of Qt, the ''KDE System Settings'' offer many more customization options that are also picked up by Qt applications.
 +
 
 +
==== 主题 ====
 +
 
 +
Several styles are already included with Qt, such as a GTK+ style, a Windows style, a CDE style, etc., but others can be installed from the official repositories or the [[AUR]] (most are written for the KDE desktop):
 +
* {{App|[[Wikipedia:Oxygen Project|Oxygen]]|A desktop theme that comes with the KDE desktop.|http://www.oxygen-icons.org/|{{Pkg|kdebase-runtime}}}}
 +
* {{App|[[Wikipedia:QtCurve|QtCurve]]|A very configurable and popular desktop theme with support for GTK+ and Qt applications.|http://kde-look.org/content/show.php?content=40492|{{Pkg|qtcurve-kde3}} {{Pkg|qtcurve-kde4}}}}
 +
* {{App|Skulpture|A GUI style addon for KDE and Qt programs that features a classical three dimensional artwork with shadows and smooth gradients to enhance the visual experience.|http://kde-look.org/content/show.php/?content=59031|{{AUR|skulpture}}}}
 +
* {{App|Polymer|A port of the KDE Plastik Style to Qt3.|http://kde-look.org/content/show.php?content=21748|{{AUR|polymer}}}}
 +
* {{App|Bespin|A very configurable KDE theme.|http://cloudcity.sourceforge.net/frame.php|{{AUR|bespin-svn}}}}
 +
 
 +
==== 字体 ====
 +
 
 +
Qt fonts can be configured from ''QtConfig'' under ''Fonts > Default Font''.
 +
 
 +
==== 图标 ====
 +
 
 +
There is no way of setting the icon theme from ''QtConfig'', but since Qt follows the [http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html Freedesktop.org Icon Specification], any theme set for X is picked up by Qt.
 +
 
 +
=== 手动配置 ===
  
*''直观的类库''
+
Qt keeps all its configuration information in {{ic|~/.config/Trolltech.conf}}. The file is rather difficult to navigate because it contains a lot of information not related to appearance, but for any changes you can just add to the end of the file and overwrite any previous values (make sure to add your modification under the {{ic|[Qt]}} header).
*''容易使用和学习''
 
*''产生高可读性、容易维护和重用的代码''
 
*''高运行性能以及小的'足迹'"''
 
  
Qt 框架正在成为主要的开发平台,同时是 [[KDE]] 软件社区的基石。
+
For example, to change the theme to QtCurve, add:
 +
{{hc|~/.config/Trolltech.conf|<nowiki>
 +
...
 +
[Qt]
 +
style=QtCurve
 +
</nowiki>}}
  
==安装==
+
=== Qt 样式表 ===
如果任何 KDE 或者依赖 Qt 的包已经安装过,{{ic|Qt}} 就已经存在了。否则,可以从 [Extra] 仓库安装它:
 
  
# pacman -S qt
+
An interesting way of customizing the look and feel of a Qt application is using Style Sheets, which are just simple CSS files. Using Style Sheets, one can modify the appearance of every widget in the application.
  
前一个版本也可以安装:
+
To run an application with a different style just execute:
 +
$ qt_application --stylesheet style.qss
  
# pacman -S qt3
+
For more information on Qt Style Sheets see the [http://qt-project.org/doc/qt-4.8/stylesheet-reference.html official documentation] or other [http://thesmithfam.org/blog/2009/09/10/qt-stylesheets-tutorial/ tutorials]. As an example Style Sheet see this [http://kde-apps.org/content/show.php/roxydoxy?content&#61;125979 Dolphin modification].
  
{{警告|[https://projects.archlinux.org/svntogit/packages.git/tree/trunk/qt.profile?h&#61;packages/qt3 安装 Qt3  影响系统 Qt 环境]。可能导致 Qt4 程序编译错误。}}
+
=== GTK+ 和 Qt ===
  
== GTK+ 和 Qt ==
 
 
如果你有 GTK+ 和 Qt 应用程序,它们的外观可能无法融合到一起。如果你希望使 GTK+ 风格与 Qt 风格匹配,请阅读 [[Uniform Look for QT and GTK Applications (简体中文)|统一 GTK+ 和 Qt 应用程序外观]].
 
如果你有 GTK+ 和 Qt 应用程序,它们的外观可能无法融合到一起。如果你希望使 GTK+ 风格与 Qt 风格匹配,请阅读 [[Uniform Look for QT and GTK Applications (简体中文)|统一 GTK+ 和 Qt 应用程序外观]].
  
==集成开发环境(IDE)==
+
== 开发 ==
有几个集成开发环境可以生产使用 Qt toolkit 的软件。
+
 
 +
=== 支持的平台 ===
 +
 
 +
Qt supports most platforms that are available today, even some of the more obscure ones, with more ports appearing every once in a while. For a more complete list see the [[Wikipedia:Qt_(framework)#Platforms|Qt Wikipedia article]].
 +
 
 +
=== 工具 ===
 +
 
 +
以下是官方 Qt 工具:
 +
 
 +
* {{App|[[Wikipedia: Qt Creator|Qt Creator]]|A cross-platform IDE tailored for Qt that supports all of its features.|http://qt.digia.com/Product/Developer-Tools/|{{Pkg|qtcreator}}}}
 +
* {{App|Qt Linguist|A set of tools that speed the translation and internationalization of Qt applications.|http://qt.digia.com/Product/Developer-Tools/|{{Pkg|qt}}}}
 +
* {{App|Qt Assistant|A configurable and redistributable documentation reader for Qt ''qch'' files.|http://qt.digia.com/Product/Developer-Tools/|{{Pkg|qt}}}}
 +
* {{App|Qt Designer|A powerful cross-platform GUI layout and forms builder for Qt widgets.|http://qt.digia.com/Product/Developer-Tools/|{{Pkg|qt}}}}
 +
* {{App|Qt Quick Designer|A visual editor for QML files which supports WYSIWYG. It allows you to rapidly design and build Qt Quick applications and components from scratch.|http://qt.digia.com/Product/Developer-Tools/|{{Pkg|qtcreator}}}}
 +
* {{App|QML Viewer|A tool for loading QML documents that makes it easy to quickly develop and debug QML applications.|http://doc.qt.digia.com/4.7-snapshot/qmlviewer.html|{{Pkg|qt}}}}
 +
* {{App|[[Wikipedia:Qmake|qmake]]|A tool that helps simplify the build process for development project across different platforms, similar to [[Wikipedia:CMake|cmake]], but with fewer options and tailored for Qt applications.|https://qt-project.org/doc/qt-4.8/qmake-manual.html|{{Pkg|qt}}}}
 +
* {{App|uic|A tool that reads ''*.ui'' XML files and generates the corresponding C++ files.|http://qt-project.org/doc/qt-4.8/uic.html|{{Pkg|qt}}}}
 +
* {{App|rcc|A tool that is used to embed resources (such as pictures) into a Qt application during the build process. It works by generating a C++ source file containing data specified in a Qt resource (.qrc) file.|http://qt-project.org/doc/qt-4.8/rcc.html|{{Pkg|qt}}}}
 +
* {{App|moc|A tool that handles Qt's C++ extensions (the signals and slots mechanism, the run-time type information, and the dynamic property system, etc.).|http://doc.qt.digia.com/4.7-snapshot/moc.html|{{Pkg|qt}}}}
 +
 
 +
=== 绑定 ===
 +
Qt has bindings for all of the more popular languages, for a full list see [[Wikipedia:Qt (framework)#Bindings|this list]].
 +
 
 +
The following examples display a small 'Hello world!' message in a window.
 +
 
 +
==== C++ ====
 +
 
 +
* Package: {{Pkg|qt4}}
 +
* Website: http://qt-project.org/
 +
* Build with: {{ic|g++ `pkg-config --cflags --libs QtCore QtGui` -o hello hello.cpp}}
 +
* Run with: {{ic|./hello}}
 +
{{hc|hello.cpp|
 +
#include <QApplication>
 +
#include <QLabel>
 +
 
 +
int main(int argc, char **argv)
 +
{
 +
    QApplication app(argc, argv);
 +
    QLabel hello("Hello world!");
 +
   
 +
    hello.show();
 +
    return app.exec();
 +
}
 +
}}
 +
 
 +
==== QML ====
 +
 
 +
* Package: {{Pkg|qt4}}
 +
* Website: http://qt-project.org/
 +
* Run with: {{ic|qmlviewer hello.qml}}
 +
{{hc|hello.qml|
 +
import QtQuick 1.0
 +
 
 +
Rectangle {
 +
    id: page
 +
    width: 400; height: 100
 +
    color: "lightgray"
 +
 
 +
    Text {
 +
        id: helloText
 +
        text: "Hello world!"
 +
        anchors.horizontalCenter: page.horizontalCenter
 +
        anchors.verticalCenter: page.verticalCenter
 +
        font.pointSize: 24; font.bold: true
 +
    }
 +
}
 +
}}
 +
 
 +
==== Python ====
 +
 
 +
* Package:
 +
** {{Pkg|pyqt}} - Python 3.x bindings
 +
** {{Pkg|python2-pyqt}} - Python 2.x bindings
 +
* Website: http://www.riverbankcomputing.co.uk/software/pyqt/intro
 +
* Run with: {{ic|python hello-pyqt.py}} or {{ic|python2 hello-pyqt.py}}
 +
{{hc|hello-pyqt.py|<nowiki>
 +
import sys
 +
from PyQt4 import QtGui
 +
 
 +
app = QtGui.QApplication(sys.argv)
 +
label = QtGui.QLabel("Hello world!")
 +
 
 +
label.show()
 +
sys.exit(app.exec_())</nowiki>
 +
}}
 +
 
 +
* Package:
 +
** {{AUR|python-pyside}} - Python 3.x bindings
 +
** {{AUR|python2-pyside}} - Python 2.x bindings
 +
* Website: http://www.pyside.org/
 +
* Run with: {{ic|python hello-pyside.py}} or {{ic|python2 hello-pyside.py}}
 +
{{hc|hello-pyside.py|<nowiki>
 +
import sys
 +
from PySide.QtCore import *
 +
from PySide.QtGui import *
 +
 +
app = QApplication(sys.argv)
 +
label = QLabel("Hello world!")
 +
 
 +
label.show()
 +
sys.exit(app.exec_())</nowiki>
 +
}}
 +
 
 +
==== C# ====
 +
 
 +
* Package: {{Pkg|kdebindings-qyoto}}
 +
* Website: http://techbase.kde.org/Development/Languages/Qyoto
 +
* Build with: {{ic|mcs -pkg:qyoto hello.cs}}
 +
* Run with: {{ic|mono hello.exe}}
 +
{{hc|hello.cs|
 +
using System;
 +
using Qyoto;
 +
 
 +
public class Hello {
 +
    public static int Main(String[] args) {
 +
        new QApplication(args);
 +
        new QLabel("Hello world!").Show();
 +
 
 +
        return QApplication.Exec();
 +
    }
 +
}
 +
}}
 +
 
 +
==== Ruby ====
 +
 
 +
* Package: {{Pkg|kdebindings-qtruby}}
 +
* Website: http://rubyforge.org/projects/korundum/
 +
* Run with: {{ic|ruby hello.rb}}
 +
{{hc|hello.rb|<nowiki>
 +
require 'Qt4'
 +
 +
app = Qt::Application.new(ARGV)
 +
hello = Qt::Label.new('Hello World!')
 +
 
 +
hello.show
 +
app.exec</nowiki>
 +
}}
 +
 
 +
==== Java ====
 +
 
 +
* Package: {{AUR|qtjambi}}
 +
* Website: http://qt-jambi.org/
 +
{{hc|Hello.java|<nowiki>
 +
import com.trolltech.qt.gui.*;
 +
 
 +
public class Hello
 +
{
 +
    public static void main(String args[])
 +
    {
 +
        QApplication.initialize(args);
 +
        QLabel hello = new QLabel("Hello World!");
 +
 
 +
        hello.show();
 +
        QApplication.exec();
 +
    }
 +
}</nowiki>
 +
}}
 +
 
 +
==== Perl ====
 +
 
 +
* Package: {{Pkg|kdebindings-perlqt}}
 +
* Website: http://code.google.com/p/perlqt4/
 +
* Run with: {{ic|perl hello.pl}}
 +
{{hc|hello.pl|<nowiki>
 +
use QtGui4;
 +
 
 +
my $a = Qt::Application(\@ARGV);
 +
my $hello = Qt::Label("Hello World!", undef);
 +
 
 +
$hello->show;
 +
exit $a->exec;
 +
</nowiki>
 +
}}
 +
 
 +
==== Lua ====
 +
 
 +
* Package: {{AUR|libqtlua}}
 +
* Website: http://www.nongnu.org/libqtlua/
 +
* Run with: {{ic|qtlua hello.lua}}
 +
{{hc|hello.lua|<nowiki>
 +
label = qt.new_widget("QLabel")
 +
 
 +
label:setText("Hello World!")
 +
label:show()</nowiki>
 +
}}
 +
 
 +
{{Note|QtLua is not designed to develop an application in pure Lua but rather to extend a Qt C++ application using Lua as scripting language.}}
  
[[Wikipedia: Qt Creator|Qt Creator]] 是 Nokia 提供的官方 IDE,可以从[community]仓库得到。({{Pkg|qtcreator}})
+
== 资源 ==
  
[[Wikipedia: QDevelop|QDevelop]] 是另一个 IDE,可以从 AUR 找到。 ({{AUR|qdevelop}})
+
* [http://qt.digia.com/ 官方网站]
 +
* [http://qt-project.org/ Qt 项目]
 +
* [http://qt-project.org/doc/qt-4.8/ Qt 文档]
 +
* [http://planet.qt-project.org/ Planet Qt]
 +
* [http://qt-apps.org/ Qt 应用程序]

Revision as of 04:38, 23 March 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Qt (简体中文)#)
翻译状态: 本文是英文页面 Qt翻译,最后翻译时间:2013-03-23,点击这里可以查看翻译后英文页面的改动。

Qt 是一个跨平台的应用程序和组件工具,它使用标准 C++,并大量地将特殊的代码生成器(称为 Meta Object Compiler,或者 moc)和数个宏并用来增强语言。它的一些重要特征包括:

  • Running on the major desktop platforms and some of the mobile platforms.
  • Extensive internationalization support.
  • A complete library that provides SQL database access, XML parsing, thread management, network support, and a unified cross-platform application programming interface (API) for file handling.

Qt 框架正在成为主要的开发平台,同时是 KDE 软件社区的基础, among other important open source and proprietary applications such as VLC, VirtualBox, Opera, Mathematica, Skype, Maya and many others.

安装

官方源中现有三个版本的 Qt,能用以下软件包来安装

  • Qt 5.x is available in the qt5-base package, with documentation in the qt5-doc package.
  • Qt 4.x is available in the qt4 package.
  • Qt 3.x is availalbe in the qt3 package, with documentation in the qt3-doc package.
Note: Qt3 is no longer developed, but there are still applications in the official repositories that depend on it. The Trinity Project is maintaining a version of Qt3 in the form of the trinity-qt3 package, available in the AUR.
Warning: Installing Qt5 affects the Qt4 environment because its binaries are in /usr/bin/. This may cause compilation failures in Qt4 applications.
警告: 安装 Qt3 会影响 Qt4 环境,因为它改变了某些 Qt 环境变量。这可能导致 Qt4 应用程序编译失败。

外观

配置

Qt application will try to mimic the behavior of the desktop environment they are running on, unless they run into some problems or hard-coded settings. For those who still want to change the look and feel of Qt application, the Qt Configuration (qtconfig or qt3config) tool is available. QtConfig offers a very simple configuration for the appearance of Qt applications that gives the user easy access to the current Qt Style, colors, fonts and other more advanced options.

Although not part of Qt, the KDE System Settings offer many more customization options that are also picked up by Qt applications.

主题

Several styles are already included with Qt, such as a GTK+ style, a Windows style, a CDE style, etc., but others can be installed from the official repositories or the AUR (most are written for the KDE desktop):

  • Oxygen — A desktop theme that comes with the KDE desktop.
http://www.oxygen-icons.org/ || kdebase-runtime
  • QtCurve — A very configurable and popular desktop theme with support for GTK+ and Qt applications.
http://kde-look.org/content/show.php?content=40492 || qtcurve-kde3 qtcurve-kde4
  • Skulpture — A GUI style addon for KDE and Qt programs that features a classical three dimensional artwork with shadows and smooth gradients to enhance the visual experience.
http://kde-look.org/content/show.php/?content=59031 || skulptureAUR
  • Polymer — A port of the KDE Plastik Style to Qt3.
http://kde-look.org/content/show.php?content=21748 || polymerAUR
  • Bespin — A very configurable KDE theme.
http://cloudcity.sourceforge.net/frame.php || bespin-svnAUR

字体

Qt fonts can be configured from QtConfig under Fonts > Default Font.

图标

There is no way of setting the icon theme from QtConfig, but since Qt follows the Freedesktop.org Icon Specification, any theme set for X is picked up by Qt.

手动配置

Qt keeps all its configuration information in ~/.config/Trolltech.conf. The file is rather difficult to navigate because it contains a lot of information not related to appearance, but for any changes you can just add to the end of the file and overwrite any previous values (make sure to add your modification under the [Qt] header).

For example, to change the theme to QtCurve, add:

~/.config/Trolltech.conf
...
[Qt]
style=QtCurve

Qt 样式表

An interesting way of customizing the look and feel of a Qt application is using Style Sheets, which are just simple CSS files. Using Style Sheets, one can modify the appearance of every widget in the application.

To run an application with a different style just execute:

$ qt_application --stylesheet style.qss

For more information on Qt Style Sheets see the official documentation or other tutorials. As an example Style Sheet see this Dolphin modification.

GTK+ 和 Qt

如果你有 GTK+ 和 Qt 应用程序,它们的外观可能无法融合到一起。如果你希望使 GTK+ 风格与 Qt 风格匹配,请阅读 统一 GTK+ 和 Qt 应用程序外观.

开发

支持的平台

Qt supports most platforms that are available today, even some of the more obscure ones, with more ports appearing every once in a while. For a more complete list see the Qt Wikipedia article.

工具

以下是官方 Qt 工具:

  • Qt Creator — A cross-platform IDE tailored for Qt that supports all of its features.
http://qt.digia.com/Product/Developer-Tools/ || qtcreator
  • Qt Linguist — A set of tools that speed the translation and internationalization of Qt applications.
http://qt.digia.com/Product/Developer-Tools/ || qt
  • Qt Assistant — A configurable and redistributable documentation reader for Qt qch files.
http://qt.digia.com/Product/Developer-Tools/ || qt
  • Qt Designer — A powerful cross-platform GUI layout and forms builder for Qt widgets.
http://qt.digia.com/Product/Developer-Tools/ || qt
  • Qt Quick Designer — A visual editor for QML files which supports WYSIWYG. It allows you to rapidly design and build Qt Quick applications and components from scratch.
http://qt.digia.com/Product/Developer-Tools/ || qtcreator
  • QML Viewer — A tool for loading QML documents that makes it easy to quickly develop and debug QML applications.
http://doc.qt.digia.com/4.7-snapshot/qmlviewer.html || qt
  • qmake — A tool that helps simplify the build process for development project across different platforms, similar to cmake, but with fewer options and tailored for Qt applications.
https://qt-project.org/doc/qt-4.8/qmake-manual.html || qt
  • uic — A tool that reads *.ui XML files and generates the corresponding C++ files.
http://qt-project.org/doc/qt-4.8/uic.html || qt
  • rcc — A tool that is used to embed resources (such as pictures) into a Qt application during the build process. It works by generating a C++ source file containing data specified in a Qt resource (.qrc) file.
http://qt-project.org/doc/qt-4.8/rcc.html || qt
  • moc — A tool that handles Qt's C++ extensions (the signals and slots mechanism, the run-time type information, and the dynamic property system, etc.).
http://doc.qt.digia.com/4.7-snapshot/moc.html || qt

绑定

Qt has bindings for all of the more popular languages, for a full list see this list.

The following examples display a small 'Hello world!' message in a window.

C++

  • Package: qt4
  • Website: http://qt-project.org/
  • Build with: g++ `pkg-config --cflags --libs QtCore QtGui` -o hello hello.cpp
  • Run with: ./hello
hello.cpp
#include <QApplication>
#include <QLabel>

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

QML

hello.qml
import QtQuick 1.0

Rectangle {
    id: page
    width: 400; height: 100
    color: "lightgray"

    Text {
        id: helloText
        text: "Hello world!"
        anchors.horizontalCenter: page.horizontalCenter
        anchors.verticalCenter: page.verticalCenter
        font.pointSize: 24; font.bold: true
    }
}

Python

hello-pyqt.py
import sys
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)
label = QtGui.QLabel("Hello world!")

label.show()
sys.exit(app.exec_())
hello-pyside.py
import sys
from PySide.QtCore import *
from PySide.QtGui import *
 
app = QApplication(sys.argv)
label = QLabel("Hello world!")

label.show()
sys.exit(app.exec_())

C#

hello.cs
using System;
using Qyoto;

public class Hello {
    public static int Main(String[] args) {
        new QApplication(args);
        new QLabel("Hello world!").Show();

        return QApplication.Exec();
    }
}

Ruby

hello.rb
require 'Qt4'
 
app = Qt::Application.new(ARGV)
hello = Qt::Label.new('Hello World!')

hello.show 
app.exec

Java

Hello.java
import com.trolltech.qt.gui.*;

public class Hello
{
    public static void main(String args[])
    {
        QApplication.initialize(args);
        QLabel hello = new QLabel("Hello World!");

        hello.show();
        QApplication.exec();
    }
}

Perl

hello.pl
use QtGui4;

my $a = Qt::Application(\@ARGV);
my $hello = Qt::Label("Hello World!", undef);

$hello->show;
exit $a->exec;

Lua

hello.lua
label = qt.new_widget("QLabel")

label:setText("Hello World!")
label:show()
Note: QtLua is not designed to develop an application in pure Lua but rather to extend a Qt C++ application using Lua as scripting language.

资源