<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Qt5 工具包簡介 > 原文: [http://zetcode.com/gui/qt5/introduction/](http://zetcode.com/gui/qt5/introduction/) 在 Qt5 教程的這一部分中,我們將介紹 Qt5 庫。 我們將安裝 Qt5 庫并創建我們的第一個小型 Qt5 應用。 Qt 最初是由挪威軟件公司 Trolltech 開發的。 2008 年,該公司被諾基亞收購。 2012 年 8 月,一家芬蘭開發公司 Digia 從諾基亞那里收購了 Qt 軟件技術。 同時,創建了一個 Qt 項目,其中開源 Qt 的開發繼續進行。 開源 Qt 工具包的網站可以在 [qt.io](http://www.qt.io) 中找到。 目前,由 Digia 的子公司 Qt 公司和開放源代碼治理下的 Qt 項目(包括個人開發者和公司)共同開發 Qt。 ## Qt Qt 是一個跨平臺的應用開發框架。 使用 Qt 開發的一些知名應用是 KDE,Opera,Google Earth,Skype,VLC,Maya 或 Mathematica。 Qt 于 1995 年 5 月首次公開發布。它具有雙重許可。 它可以用于創建開源應用以及商業應用。 Qt 工具箱是一個非常強大的工具箱。 它在開源社區中已經建立。 全世界有成千上萬的開源開發者在使用 Qt。 ## 下載并解壓縮 我們轉到 [download.qt.io/official_releases/qt/](http://download.qt.io/official_releases/qt/) 頁面。 (由于下載鏈接過去經常更改,因此您可能需要用 Google 搜索當前鏈接。)我們選擇最新的 Qt 5.x 來源。 在創建本教程時,最新的數據是 Qt 5.5.1。 接下來,我們將從源代碼安裝 Qt。 ```cpp $ ls qt-everywhere-opensource-src-5.5.1.tar.gz qt-everywhere-opensource-src-5.5.1.tar.gz ``` 從下載頁面,我們下載 Qt5 源。 我們使用 TAR 文件。 (我們為自己省了一些麻煩。ZIP 文件具有 Windows 行尾。) ```cpp $ tar -xzvf qt-everywhere-opensource-src-5.5.1.tar.gz ``` 該命令會將所有文件解壓縮到目錄`qt-everywhere-opensource-src-5.5.1/`。 ```cpp $ du -hs qt-everywhere-opensource-src-5.5.1 2.0G qt-everywhere-opensource-src-5.5.1 ``` 現在目錄的大小為 2G。 ```cpp $ cd qt-everywhere-opensource-src-5.5.1/ ``` 我們轉到創建的目錄。 在`README`文件中,有安裝說明。 安裝簡單明了,但需要花費大量時間。 ## 從源安裝 在開始構建 Qt5 之前,我們可能需要安裝一些其他庫。 例如,如果要從 Qt 連接到 MySQL,則需要在系統上安裝`libmysqld-dev`。 我們以經典方式安裝庫。 在 Unix 系統上,軟件的安裝分為三個步驟。 * 配置 * 構建 * 安裝 ```cpp $ ./configure -prefix /usr/local/qt5 Which edition of Qt do you want to use ? Type 'c' if you want to use the Commercial Edition. Type 'o' if you want to use the Open Source Edition. ``` 首先,我們運行配置腳本。 該腳本將詢問我們是否需要 Qt5 庫的商業版或開源版。 該腳本將為我們的機器類型配置庫。 默認情況下,Qt 將安裝在`/usr/local/Qt-5.5.1/`目錄中。 這可以通過配置腳本的`-prefix`參數進行更改。 我們將庫安裝到`/usr/local/qt5/`目錄中。 請注意,此處的安裝字有兩個含義。 這是整個過程,包括所有三個步驟。 這也意味著“將文件移動到特定目錄”,這是最后第三步。 ```cpp This is the Open Source Edition. You are licensed to use this software under the terms of the Lesser GNU General Public License (LGPL) versions 2.1. You are also licensed to use this software under the terms of the GNU General Public License (GPL) versions 3. Type '3' to view the GNU General Public License version 3. Type 'L' to view the Lesser GNU General Public License version 2.1. Type 'yes' to accept this license offer. Type 'no' to decline this license offer. Do you accept the terms of either license? yes ``` 確認許可協議。 ```cpp Running configuration tests... The test for linking against libxcb and support libraries failed! You might need to install dependency packages, or pass -qt-xcb. ``` 如果腳本失敗并顯示上述消息,則我們需要安裝一些其他 xcb 庫,或者使用`-qt-xcb`選項再次運行該腳本。 ```cpp $ ./configure -prefix /usr/local/qt5 -qt-xcb ``` 使用`-qt-xcb`選項,可以構建某些庫,而不是針對系統庫進行鏈接。 ```cpp ... Qt modules and options: Qt D-Bus ............... yes (loading dbus-1 at runtime) Qt Concurrent .......... yes Qt GUI ................. yes Qt Widgets ............. yes Large File ............. yes QML debugging .......... yes Use system proxies ..... no ... SQL drivers: DB2 .................. no InterBase ............ no MySQL ................ yes (plugin) OCI .................. no ODBC ................. no PostgreSQL ........... yes (plugin) SQLite 2 ............. no SQLite ............... yes (plugin, using bundled copy) TDS .................. no tslib .................. no udev ................... yes xkbcommon-x11........... yes (bundled copy, XKB config root: /usr/share/X11/xkb) xkbcommon-evdev......... yes zlib ................... yes (system library) Qt is now configured for building. Just run 'make'. Once everything is built, you must run 'make install'. Qt will be installed into /usr/local/qt5 Prior to reconfiguration, make sure you remove any leftovers from the previous build. ``` 這是配置腳本的部分輸出。 輸出告訴我們準備構建哪些組件。 例如,將創建用于 MySQL 和 PostgreSQL 的 SQL 驅動程序,而不用于 DB2 或 InterBase。 ```cpp $ make ``` 我們使用`make`命令開始構建過程。 Qt 工具包的構建可能要花費幾個小時。 這取決于處理器的能力。 最后一步是安裝文件或將文件移動到目錄中。 ```cpp $ sudo make install ``` 此命令完成安裝過程。 該庫現在安裝在`/usr/local/qt5/`目錄中。 我們要做的最后一件事是將 Qt5 路徑添加到`PATH`系統變量。 bash 用戶需要編輯`.profile`文件或`.bashrc`文件。 ```cpp $ PATH=/usr/local/qt5/bin:$PATH $ export PATH ``` 我們已經將 Qt5 庫的 bin 目錄的路徑添加到`PATH`環境變量。 再次登錄后,更改將處于活動狀態。 ## 從包安裝 從包安裝 Qt 更加容易。 Linux 包通常不包含最新的 Qt 版本。 ```cpp $ sudo apt-get install qt5-default ``` 上面的命令在基于 Debian 的 Linux 上安裝 Qt5。 ## 版本 我們的第一個程序打印 Qt5 庫的版本。 `version.cpp` ```cpp #include <QtCore> #include <iostream> int main() { std::cout << "Qt version: " << qVersion() << std::endl; } ``` `qVersion()`函數在運行時以字符串形式返回 Qt 的版本號。 ```cpp $ g++ -o version version.cpp -I/usr/local/qt5/include/QtCore -I/usr/local/qt5/include -L/usr/local/qt5/lib -lQt5Core -fPIC ``` 上面的命令將編譯示例。 請注意,您的 Qt5 庫可能安裝在其他位置。 ```cpp $ ./version Qt version: 5.5.1 ``` 本教程中使用的 Qt5 庫的版本是 5.5.1。 ## 測試一個小的 GUI 示例 最后,我們編寫一個小應用。 該應用包含一個普通窗口。 `simple.cpp` ```cpp #include <QApplication> #include <QWidget> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.resize(250, 150); window.setWindowTitle("Simple example"); window.show(); return app.exec(); } ``` 要構建此示例,我們使用`qmake`工具。 ```cpp $ qmake -project ``` 該命令創建一個擴展名為`.pro`的項目文件。 `simple.pro` ```cpp ###################################################################### # Automatically generated by qmake (3.0) Fri Oct 30 17:11:00 2015 ###################################################################### TEMPLATE = app TARGET = simple INCLUDEPATH += . # Input SOURCES += simple.cpp QT += widgets ``` 默認情況下,項目中不包括 Qt Widgets 模塊。 因此,我們將模塊添加到文件的末尾。 ```cpp $ qmake $ make ``` 我們使用上述命令構建程序。 `qmake`創建一個`Makefile`,`make`命令生成該程序。 如果 Qt5 安裝目錄不是`PATH`變量的一部分,我們可以提供`qmake`工具的完整路徑。 ```cpp $ /usr/local/qt5/bin/qmake -project $ /usr/local/qt5/bin/qmake $ make ``` ![Simple example](https://img.kancloud.cn/24/aa/24aadd0240e978e0f93a92e1c265c6cb_252x176.jpg) 圖:簡單 example 本章是 Qt5 庫的簡介。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看