(二)第一個簡單的程序-HelloWorld

    新建工程

        打開Qt Creator 文件-新建文件或項目-其他項目-空的Qt項目-choose-名稱:01_HelloWorld 創建路徑:E:\Study\Self-study\Qt\CSDN\Code(注意:此路徑必須爲英文路徑,不然編譯會出錯。)-下一步-下一步-完成。



     

    新建c++源文件


        新建文件或項目-文件和類-C++-C++ Sources File-choose...-名稱:main,路徑不修改-下一步-完成。



main.cpp文件中添加代碼:

/**
    Qt4.8
    Hello,world.
    你好,世界。
    2014.04.18
    IFPELSET
*/
#include <QApplication>
#include <QLabel>
#include <QTextCodec>

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

    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));

    QLabel labelEng("Hello,world.");
    QLabel labelChn(QObject::tr("你好,世界。"));

    labelEng.move(300, 200);
    labelChn.move(300, 300);
    labelEng.show();
    labelChn.show();

    return app.exec();
}

/**
    Qt5.2
    在pro文件中添加 QT += widgets
    IFPELSET
*/
#include <../QtWidgets/QApplication>
#include <../QtWidgets/QLabel>

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

    QLabel labelEng("Hello,world.");
    QLabel labelChn("你好,世界。");

    labelEng.move(300, 200);
    labelChn.move(300, 300);
    labelEng.show();
    labelChn.show();

    return app.exec();
}

    程序運行結果:








發佈了38 篇原創文章 · 獲贊 2 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章