个人工具

Qt开发

来自Ubuntu中文

Tusooa讨论 | 贡献2009年7月28日 (二) 12:46的版本 Hello World

跳转至: 导航, 搜索

编辑中


Qt是跨平台的C++图形开发框架,发家史/辛酸史详细去看wikipedia,KDE环境就是用Qt开发的,最新的版本是Qt4.5.1。

编译环境

Hello World

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

编译:

qmake -project 
qmake 
make

Qtcreator

Qt4.5后 附带的轻量级IDE开发环境。

Qtcreator.png

安装

sudo apt-get install qt-creator


中文界面

如果安装的qtcreator是显示英文菜单,需要安装KDE的中文包才能显示中文菜单。

sudo apt-get install language-pack-kde-zh language-pack-kde-zh-base

待编辑

编译环境

安装KDE 开发环境:

sudo aptitude install kde-devel build-essential xorg-dev cdbs debhelper cmake \
kdesdk-scripts subversion ssh xserver-xephyr doxygen dbus-x11 \
libxml2-dev libxslt1-dev shared-mime-info libical-dev libgif-dev libssl-dev \
libboost-dev libboost-program-options-dev libgpgme11-dev libxine-dev \
libqimageblitz-dev libbz2-dev libdbus-1-dev libpam0g-dev libpcre3-dev \ 
libkrb5-dev libsm-dev libclucene0ldbl libclucene-dev libjpeg62-dev \
libxtst-dev xsltproc libxrender-dev libfontconfig1-dev automoc4

Hello World

#include <KApplication>                                                             
#include <KAboutData>                                                               
#include <KCmdLineArgs>                                                             
#include <KMessageBox>                                                              
                                                                                    
int main (int argc, char *argv[])                                                   
{                                                                                   
    KAboutData aboutData(                                                           
                         // The program name used internally.                       
                         "tutorial1",                                               
                         // The message catalog name
                         // If null, program name is used instead.
                         0,
                         // A displayable program name string.
                         ki18n("Tutorial 1"),
                         // The program version string.
                         "1.0",
                         // Short description of what the app does.
                         ki18n("Displays a KMessageBox popup"),
                         // The license this code is released under
                         KAboutData::License_GPL,
                         // Copyright Statement
                         ki18n("(c) 2007"),
                         // Optional text shown in the About box.
                         // Can contain any information desired.
                         ki18n("Some text..."),
                         // The program homepage string.
                         "http://tutorial.com/",
                         // The bug report email address
                         "submit@bugs.kde.org");

    KCmdLineArgs::init( argc, argv, &aboutData );
    KApplication app;
    KGuiItem yesButton( i18n( "Hello" ), QString(),
                        i18n( "This is a tooltip" ),
                        i18n( "This is a WhatsThis help text." ) );
    KMessageBox::questionYesNo( 0, i18n( "Hello World" ),
                                i18n( "Hello" ), yesButton );
    return 0;
}

保存为main.cpp

现在需要一个CMakeLists.txt:

project (tutorial1)
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include_directories(${KDE4_INCLUDES})
set(tutorial1_SRCS main.cpp)
kde4_add_executable(tutorial1 ${tutorial1_SRCS})
target_link_libraries(tutorial1 ${KDE4_KDEUI_LIBS})
install(TARGETS tutorial1  ${INSTALL_TARGETS_DEFAULT_ARGS})

编译:

mkdir build && cd build
cmake ..
make
./tutorial1

KDevelop

KDE开发的IDE,最新的稳定版是qt3.5做的,移植qt4的还在开发中。

安装

sudo apt-get install kdevelop


KDE 4版本

  • SynapitcKPackageKit里搜索kdevelop-kde4(如果是Karmic Koala,就是kdevelop),安装
  • Firefox浏览器地址栏中输入apt:kdevelop-kde4(如果是Karmic Koala,就是kdevelop)
  • 命令安装:
sudo aptitude install kdevelop-kde4 #(如果是Karmic Koala,就是kdevelop)

中文界面

如果安装的qtcreator是显示英文菜单,需要安装KDE的中文包才能显示中文菜单。

sudo apt-get install language-pack-kde-zh language-pack-kde-zh-base

Monkeystudio

轻量级的IDE,monkeystudio官网

Netbean

Eclipse

外部链接

维基百科对Qt的介绍

官方

Qt官方主页

Qt 源代码

Qt 实验室

Qt 在线文档

教学与参考文件

Qt4 學習筆記

Qt 教學

learnqt英文blog

论坛

Qt 社群網站

google论坛

Qt中文邮件列表

Qt/Qtopia中文论坛

Qt中文论坛 另一个Qt中文论坛 Qt Everywhere

Planet

planetqt planetkde

书籍

《C++ GUI Qt4 编程(第二版)》

参考

KDE TechBase Kubuntu 编译环境