歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 在Ubuntu上用命令創建你的第一個Qt程序

在Ubuntu上用命令創建你的第一個Qt程序

日期:2017/3/1 10:06:43   编辑:Linux編程

注:本文檔假定你已經在Ubuntu下成功的安裝Qt SDK在您的操作系統。如果沒有安裝,請參考此網址:http://www.linuxidc.com/Linux/2012-11/74757.htm

steps:

1->打開一個終端,輸入如下命令將創建一個Qt程序的主目錄

mkdir QtHelloWorld

2->通過輸入如下命令更改到的QtHelloWorld目錄

cd QtHelloWorld

3->在QtHelloWorld目錄下,我們要創建我們的Qt程序的源代碼文件

gedit main.cpp

4->現在將底部的代碼添加到您的main.cpp的源代碼文件,將文件保存並退出

5->在QtHelloWorld目錄下,輸入如下命令:

qmake -project

qmake

make

6->在QtHelloWorld目錄下會有一個“QtHelloWorld”可執行文件,輸入如下命令即可運行:

./QtHelloWorld

  1. #include <QApplication>
  2. #include <QLabel>
  3. #include <QWidget>
  4. int main(int argc, char *argv[ ])
  5. {
  6. QApplication app(argc, argv);
  7. QLabel hello("<center>Welcome to my first WikiHow Qt program</center>");
  8. hello.setWindowTitle("My First WikiHow Qt Program");
  9. hello.resize(400, 400);
  10. hello.show();
  11. return app.exec();
  12. }
Copyright © Linux教程網 All Rights Reserved