(原)Ubuntu下安装Qt
(摘)QT中.pro文件解析

(原)Qt之HelloWorld

孔令春 posted @ 2009年9月21日 05:43 in 开发语言 with tags Qt之HelloWorld , 4932 阅读

        怪了,好像学任何语言都是从Hello world的,呵呵,Qt也不例外。

代码如下:

 

/*  Hello/hello.cpp   */

#include <QApplication>
#include <QMainWindow>
#include <QCore/QTextCodec>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication app(argc,argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName(
"utf-8"));
QMainWindow *window = new QMainWindow; window->setWindowTitle("Hello Qt"); QLabel *label = new QLabel("<h2><font color =         red><i>Hello</i></font>" "<b>World!</b></h2>"); label->setAlignment(Qt::AlignCenter); //居中对齐 window->setCentralWidget(label); //将Label设置为中间部件 window->adjustSize(); //调整窗口到合适大小 window->show(); return app.exec(); }



必須的东西:

#include <QApplication>

int main(int argc,char *argv[])
{
     QApplication app(argc,argv);
     ...
     return app.exec();
}



编译:
    qmake -project    ---生成Qt的项目文件
    qmake                 ---生成MakeFile文件
    make                   ---执行MakeFile文件(调用g++编译)

注意:
    生成的项目文件名,默认是与上一级文件夹同名的,所以建议你最好为你的程序单独建一个文件夹。

 

 

Avatar_small
TN Board Model Paper 说:
2022年8月19日 20:40

Tamilnadu Board Model Paper 2023 Class 6 Pdf Download with Answers for Tamil Medium, English Medium, Hindi Medium, Urdu Medium & Students for Small Answers, Long Answer, Very Long Answer Questions, and Essay Type Questions to Term1 & Term2 Exams at official website. TN Board Model Paper Class 6 New Exam Scheme or Question Pattern for Sammittive Assignment Exams (SA1 & SA2): Very Long Answer (VLA), Long Answer (LA), Small Answer (SA), Very Small Answer (VSA), Single Answer, Multiple Choice and etc.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter