python hello world程序编写 linux_在Ubuntu上编写Qt Helloworld程序

不使用Qt Creator IDE的情况下,我只使用自己喜欢的Emacs和命令行来创建一个hello world工程。

1. 确保/usr/bin/qmake指向Qt 5.2.0安装的qmake

/usr/bin# mv qmake qmake_bk

/usr/bin# ln -s /home/likewise-open/CHN/shu6889/Qt5.2.0/5.2.0/gcc_64/bin/qmake ./qmake

2. 写代码:

创建helloworld目录,添加main.cc文件

#include

#include

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

QApplication app(argc, argv);

QLabel hello("

Welcome to my first WikiHow Qt program
");

hello.setWindowTitle("My First WikiHow Qt Program");

hello.resize(400, 400);

hello.show();

return app.exec();

}

3. 创建project文件

在helloworld目录下,运行下面的命令:

qmake -project

现在,我得到了helloworld.pro文件。

######################################################################

# Automatically generated by qmake (3.0) ?? 12? 16 15:49:40 2013

######################################################################

TEMPLATE = app

TARGET = helloworld

INCLUDEPATH += .

# Input

SOURCES += main.cc

4. 编译

运行qmake,不带参数。这样就得到了Makefile文件。

qmake

make

得到-lGL的链接错误,安装mesa

apt-get install libgl1-mesa-dev

但是得到了一些新的链接错误:

main.o: In function `main':

main.cc:(.text.startup+0x27): undefined reference to `QApplication::QApplication(int&, char**, int)'

main.cc:(.text.startup+0x56): undefined reference to `QLabel::QLabel(QString const&, QWidget*, QFlags)'

main.cc:(.text.startup+0x84): undefined reference to `QWidget::setWindowTitle(QString const&)'

main.cc:(.text.startup+0xa9): undefined reference to `QWidget::resize(QSize const&)'

main.cc:(.text.startup+0xb1): undefined reference to `QWidget::show()'

main.cc:(.text.startup+0xb6): undefined reference to `QApplication::exec()'

main.cc:(.text.startup+0xc1): undefined reference to `QLabel::~QLabel()'

main.cc:(.text.startup+0xc9): undefined reference to `QApplication::~QApplication()'

main.cc:(.text.startup+0xe5): undefined reference to `QApplication::~QApplication()'

main.cc:(.text.startup+0x106): undefined reference to `QLabel::~QLabel()'

main.cc:(.text.startup+0x118): undefined reference to `QLabel::~QLabel()'

collect2: error: ld returned 1 exit status

make: *** [helloworld] Error 1

在helloworld.pro文件中添加一行:

QT += widgets

重新编译。好了。

运行hellowordl程序,看到Qt窗口了。

140625142146871.png

当切换到Windows上开发时,可以不使用命令行开发。直接用Qt Creator打开这个helloworld.pro文件,会默认使用一些配置。编译运行,成功了。

Qt 的详细介绍:请点这里

Qt 的下载地址:请点这里

logo.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值