使用 Qt 與 Visual C++ 2008 創建應用程序事例
在壇子里面逛,發現了一片好文章,為大家推薦一下。本文學習的目的::學會如何使用 Visual C++ 命令提示和生成文件項目創建一個簡單的Qt應用程序步驟::
安裝 Qt libraries for windows(VS 2008), 該文件下載地址 http://qt.nokia.com/downloads , 選擇 LGPL. 還可在該地址下載 Qt SDK for Windows, qt-vs-addin.
增加環境變量 QTDIR, 其值為Qt的安裝目錄, 例如: D:\Qt-4.4.3. 修改環境變量 Path, 將 Qt的"bin"目錄添加至其內.
在一個新的目錄里創建 Hello.cpp 文件. 代碼如下:
- #include "QApplication"
- #include "QPushButton"
- int main(int argc, char *argv[]) {
- QApplication app(argc, argv);
- QPushButton hello("Hello world");
- hello.resize(100, 30);
- hello.show();
- return app.exec();
- }
- #include "QApplication"
- #include "QPushButton"
- int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
- QPushButton hello("Hello world");
- hello.resize(100, 30);
- hello.show();
- return app.exec();
- }
啟動 Visual Studio 2008 命令提示, 使用磁盤符號和cd命令移動至 hello.cpp 文件所在的目錄
鍵入 如下的命令
- qmake -project -0 hello.pro
- qmake hello.pro
- nmake
這樣就在debug目錄中生成了文件 hello.exe
如果要使用 Visual Studio Express IDE, 還需要進行一些步驟: 選擇菜單"工具>選項>項目和解決方案>VC++目錄", 在包含文件中增加"$(QTDIR)\include", "$(QTDIR)\include\QtCore", "$(QTDIR)\include\QtGui". 在庫文件中增加 "$(QTDIR)\lib".
創建一個新的項目("文件>新建>項目>Visual C++>常規>生成文件項目"), 名稱為"HelloQt"
選擇菜單"項目>屬性>配置屬性>NMake", 生成命令行中寫入"qmake -project && qmake && nmake release-all", 輸出中則寫"release\HelloQt.exe"
添加新文件"HelloQt.cpp", 輸入上面的代碼
使用快捷鍵 "Ctrl-F5" 或者菜單"調試>開始執行(不調試)", 則生成了 HelloQt.exe
小結::使用 Qt 與 Visual C++ 2008 創建應用程序事例的內容介紹完了,VS代碼顏色背景方案是不是挺炫的?嘿嘿,希望本文能對你有所幫助!