Qt 中如何创建和使用库

库 将经常用到的程序模块化,制作成库。库的概念给编程带来明显的好处,不需要因为要开发或修改一个小软件,就要重写、编译大量的源代码,降低了开发难度,节约了可观的时间。 程序编译成可执行程序的过程一般包括:预处理、编译、汇编和链接几个步骤。我们所说的库就是在链接过程中用到的(动态库的显式链接除外),对不同类型的库有不同的处理模式。 库常分为动态库(共享库)和静态库。链接阶段使用静态库的方式是从静态库中获取用到的程序并集成到目标程序中(静态地存在),以后使用程序的时候就不再需要到静态库中去找了。而与之相对,动态库则在链接过程中不集成到目标程序中去,使用时动态地加载。 静态库文件的后缀一般是 .lib、.a,动态库文件的后缀一般是 .dll、.s...

初识 QSS

简介 CSS( Cascading Style Sheets,层叠样式表)把现在的网页打扮的或花枝招展、或简约朴素。使用 CSS 将结构和表现分离的设计理念启发了 Qt 的样式设计,于是出现了 QSS( Qt Style Sheets ),给界面的开发增添了极大的灵活性。这就好比界面部件( Widget )结构化了人的衣着(帽子、上衣、裙子、鞋子),QSS 则定义了这些衣服的颜色、花纹等样式,每天只需关注换什么样式即可,不用去想要不要穿裙子(当然,你非要穿裤子也是没问题的...

Qt 往事

那是 1990 年的一个夏日,Haavard 与 Eirik 暂时从繁重的项目中解脱,他们难得如此慵懒地倚坐在斑驳的树荫下。 “咳~”,Haavard 感叹道,仿佛得到解脱。 Eirik :“咋的了哥们?”(你不是明知故问吗~) “这么干下去不是个事儿啊!大好的光阴就从指间流去,抓也抓不住……”,Haavard 盯着手里的光斑,直愣愣地...

闲聊 3D

3D( 3 Dimensions ),即 3 维,3 次元。何为 3D?具有长、宽、高三个维度。我们人类所处的世界就是 3D 的世界,我们世界的投影则是 2D 的,就像我们的影...

STM32 软件模板

创建文件目录如下: Doc 用于存放文档; Libraries 用于存放各种库,其中的 STM32Lib 是不可缺少的内核与标准外设的驱动库。原则上,所有的库都不要做任何修改,保持与原始发行状态一致。 MDK-ARM 是与 RVMDK 编译器相关的文件夹,存放工程文件、各种输出文件等; User 目录用于存放我们自己开发的代码 mcu 为 MCU 外设驱动程序文件夹; lib 为一些库程序的文件夹; bsp 为其他板载器件的驱动程序。 MDK 开发环境只支持一级组结构,所以组结构就是扁平化了的。一般包含 STM32Lib、Startup、User、Doc 等组。 把内核及标准外设的驱动(C 文件)加入 STM32Lib 组: Startup 为启动代码组,要从 .\Libraries\STM32Lib\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm 文件夹选择一个。 将 main.c、配置、中断服务等文件加入 User 文件夹并加载到 User 组。 stm32f10x_conf.h 头文件在 stm32f10x.h 中通过判断有无 USE_STDPERIPH_DRIVER 宏定义而确定是否引用。 此外还需要配置工程,定义单片机系列(如定义 STM32F10X_CL)、选择使用标准外设驱动库 USE_STDPERIPH_DRIVER Include Paths 中配置所有需要引用的头文件所在目录 配置时钟晶体的频率 在需要操作内核或标准外设的地方直接引用库的头文件(stm32f10x.h)即可: 在编译的时候可以看到所有的库文件都被编译了,速度很慢,如果没有使用某个库文件,可以选择不编译它。 取消选择 Include in Target Build 即可。 在 C/C++ 选项卡中选中 One ELF Section per Function 选项可将用不到的函数排除在编译结果之外,从而减小生成程序的大...

正则表达式

很早之前做网站就接触过这个东东了,不过由于用的比较少,总是学了忘、忘了学,一知半解。现在来看大量的常用工具都支持了正则表达式,比如 Everything、编辑器...

搭建 Qt5.1.1 + VS2010 集成开发环境及 Qt 静态库的编译方法

1、下载 Qt SDK(Software Development Kit,即软件开发工具包)的安装包:Qt 5.1.1 for Windows 32-bit (VS 2010, 505 MB) http://download.qt-project.org/official_releases/qt/5.1/5.1.1/qt-windows-opensource-5.1.1-msvc2010-x86-offline.exe 该安装包中包含了 Qt Creator 2.8.1,使用的是官方编译好的动态库。 2、下载 VS2010 的 Qt 插件:Visual Studio Add-in 1.2.2 for Qt5 http://download.qt-project.org/official_releases/vsaddin/qt-vs-addin-1.2.2-opensource.exe 3、在 VS2010 中配置 Qt 3.1 选择 Qt 库: 3.2 打开一个 Demo 编译一下看看: 很炫的效果。 4、编译静态库 用动态库编译发布的软件需要打包一系列的 DLL 才能在没有 Qt 环境的电脑上运行,有时候会显得很麻烦,希望能够生成一个单文件的 exe 程序。这时就需要静态编译了,相应地需要静态库的支持。通过配置编译 Qt 的源代码来产生静态库: 4.1 下载 qt-everywhere-opensource-src-5.1.1 http://download.qt-project.org/official_releases/qt/5.1/5.1.1/single/qt-everywhere-opensource-src-5.1.1.zip 4.2 将源代码解压到非中文目录 D:\qt-everywhere-opensource-src-5.1.1\(举例) 4.3 编译配置 4.3.1 修改 qtbase\mkspecs\win32-msvc2012\qmake.conf 文件,将: QMAKE_CFLAGS_RELEASE = -O2 -MD QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi QMAKE_CFLAGS_DEBUG = -Zi -MDd 改为: QMAKE_CFLAGS_RELEASE = -O2 -MT QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi QMAKE_CFLAGS_DEBUG = -Zi -MTd   这样对于对 VC 的链接库也将静态编译。 4.3.2 在 Visual Studio 命令提示界面进入源码的 qtbase 目录 4.3.3 运行 configure 进行配置,配置包含 odbc、sqlite,跳过 webkit cd D:\qt-everywhere-opensource-src-5.1.1\qtbase configure  -prefix  C:\Qt\Qt5.1.1\5.1.1\msvc2010-static -confirm-license -opensource -platform win32-msvc2010 -debug-and-release -static -qt-sql-sqlite -qt-sql-odbc -plugin-sql-sqlite -plugin-sql-odbc -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -qt-freetype -no-qml-debug -no-angle -nomake tests -nomake examples -skip qtwebkit Usage: configure [options] Installation options: These are optional, but you may specify install directories.     -prefix <dir> ...... This will install everything relative to <dir>                          (default $QT_INSTALL_PREFIX)     -hostprefix [dir] .. Tools and libraries needed when developing                          applications are installed in [dir]. If [dir] is not                          given, the current build directory will be used.                          (default PREFIX) You may use these to separate different parts of the install:     -bindir <dir> ...... User executables will be installed to <dir>                          (default PREFIX/bin)     -libdir <dir> ...... Libraries will be installed to <dir>                          (default PREFIX/lib)     -headerdir <dir> ... Headers will be installed to <dir>                          (default PREFIX/include)     -archdatadir <dir> . Architecture-dependent data used by Qt will be                          installed to <dir>                          (default PREFIX)     -libexecdir <dir> .. Program executables will be installed to <dir>                          (default ARCHDATADIR/bin)     -plugindir <dir> ... Plugins will be installed to <dir>                          (default ARCHDATADIR/plugins)     -importdir <dir> ... Imports for QML1 will be installed to <dir>                          (default ARCHDATADIR/imports)     -qmldir <dir> ...... Imports for QML2 will be installed to <dir>                          (default ARCHDATADIR/qml)     -datadir <dir> ..... Data used by Qt programs will be installed to <dir>                          (default PREFIX)     -docdir <dir> ...... Documentation will be installed to <dir>                          (default DATADIR/doc)     -translationdir <dir> Translations of Qt programs will be installed to                           <dir>                           (default DATADIR/translations)     -examplesdir <dir> . Examples will be installed to <dir>                          (default PREFIX/examples)     -testsdir <dir> .... Tests will be installed to <dir>                          (default PREFIX/tests)     -hostbindir <dir> .. Host executables will be installed to <dir>                          (default HOSTPREFIX/bin)     -hostlibdir <dir> .. Host libraries will be installed to <dir>                          (default HOSTPREFIX/lib)     -hostdatadir <dir> . Data used by qmake will be installed to <dir>                          (default HOSTPREFIX) Configure options:  The defaults (*) are usually acceptable. A plus (+) denotes a default value  that needs to be evaluated. If the evaluation succeeds, the feature is  included. Here is a short explanation of each option:     -release ........... Compile and link Qt with debugging turned off.  * -debug ............. Compile and link Qt with debugging turned on.  + -debug-and-release . Compile and link two Qt libraries, with and without                          debugging turned on.     -force-debug-info .. Create symbol files for release builds.     -developer-build ... Compile and link Qt with Qt developer options                          (including auto-tests exporting)     -opensource ........ Compile and link the Open-Source Edition of Qt.     -commercial ........ Compile and link the Commercial Edition of Qt.     -c++11 ............. Compile Qt with C++11 support enabled.     -no-c++11 .......... Do not compile Qt with C++11 support enabled.  * -shared ............ Create and use shared Qt libraries.     -static ............ Create and use static Qt libraries.     -ltcg .............. Use Link Time Code Generation. (Release builds only)  * -no-ltcg ........... Do not use Link Time Code Generation.     -make <part> ....... Add part to the list of parts to be built at make time                            libs                            tools                            examples     -nomake <part> ..... Exclude part from the list of parts to be built.     -skip <module> ..... Exclude an entire module from the build.     -no-compile-examples Install only the sources of examples.     -no-widgets ........ Disable Qt Widgets module.     -no-gui ............ Disable Qt GUI module.     -no-accessibility .. Disable accessibility support.      ................... Disabling accessibility is not recommended, as it will                          break QStyle                          and may break other internal parts of Qt.                          With this switch you create a source incompatible                          version of Qt,                          which is unsupported.  * -accessibility ..... Enable accessibility support.     -no-sql-<driver> ... Disable SQL <driver> entirely, by default none are                          turned on.     -qt-sql-<driver> ... Enable a SQL <driver> in the Qt Library.     -plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to at run                          time.                          Available values for <driver>:                            mysql                            psql                            oci                            odbc                            tds                            db2  + sqlite                            sqlite2                            ibase                          (drivers marked with a '+' have been detected as                          available on this system)     -system-sqlite ..... Use sqlite from the operating system.     -no-opengl ......... Do not support OpenGL.     -opengl <api> ...... Enable OpenGL support with specified API version.                          Available values for <api>:                            desktop - Enable support for Desktop OpenGL                            es1 - Enable support for OpenGL ES Common Profile  * es2 - Enable support for OpenGL ES 2.0  * -no-openvg ......... Disables OpenVG functionality.     -openvg ............ Enables OpenVG functionality.     -force-asserts ..... Activate asserts in release mode.     -platform <spec> ... The operating system and compiler you are building on.                          (default %QMAKESPEC%)     -xplatform <spec> .. The operating system and compiler you are cross                          compiling to.                          See the README file for a list of supported operating                          systems and compilers.     -sysroot <dir> ..... Sets <dir> as the target compiler's and qmake's                          sysroot and also sets pkg-config paths.     -no-gcc-sysroot .... When using -sysroot, it disables the passing of                          --sysroot to the compiler.  * -no-nis ............ Do not compile NIS support.     -nis ............... Compile NIS support.     -neon .............. Enable the use of NEON instructions.  * -no-neon ........... Do not enable the use of NEON instructions.     -no-iconv .......... Do not enable support for iconv(3).  + -iconv ............. Enable support for iconv(3).  + -sun-iconv ......... Enable support for iconv(3) using sun-iconv.  + -gnu-iconv ......... Enable support for iconv(3) using gnu-libiconv.  + -inotify ........... Explicitly enable Qt inotify(7) support.     -no-inotify ........ Explicitly disable Qt inotify(7) support.  + -eventfd ........... Enable eventfd(7) support in the UNIX event loop.     -no-eventfd ........ Disable eventfd(7) support in the UNIX event loop.  * -largefile ......... Enables Qt to access files larger than 4 GB.     -fontconfig ........ Build with FontConfig support.  * -no-fontconfig ..... Do not build with FontConfig support.     -posix-ipc ......... Enable POSIX IPC.     -glib .............. Compile Glib support.     -sysconfdir <dir> .. Settings used by Qt programs will be looked for in                          <dir>.     -system-proxies .... Use system network proxies by default.  * -no-system-proxies . Do not use system network proxies by default.  + -warnings-are-errors Make warnings be treated as errors.     -no-warnings-are-errors Make warnings be treated normally.     -qtnamespace <name> Wraps all Qt library code in 'namespace name {...}'.     -qtlibinfix <infix> Renames all Qt* libs to Qt*<infix>.     -D <define> ........ Add an explicit define to the preprocessor.     -I <includepath> ... Add an explicit include path.     -L <librarypath> ... Add an explicit library path.     -l <libraryname> ... Add an explicit library name, residing in a                          librarypath.     -help, -h, -? ...... Display this information. Third Party Libraries:     -qt-zlib ........... Use the zlib bundled with Qt.  + -system-zlib ....... Use zlib from the operating system.                          See http://www.gzip.org/zlib     -qt-pcre ........... Use the PCRE library bundled with Qt.     -system-pcre ....... Use the PCRE library from the operating system.                          See http://pcre.org/  + -icu ............... Use the ICU library.     -no-icu ............ Do not use the ICU library.                          See http://site.icu-project.org/     -no-gif ............ Do not compile GIF reading support.     -no-libpng ......... Do not compile PNG support.     -qt-libpng ......... Use the libpng bundled with Qt.  + -system-libpng ..... Use libpng from the operating system.                          See http://www.libpng.org/pub/png     -no-libjpeg ........ Do not compile JPEG support.     -qt-libjpeg ........ Use the libjpeg bundled with Qt.  + -system-libjpeg .... Use libjpeg from the operating system.                          See http://www.ijg.org     -no-freetype ....... Do not compile in Freetype2 support.  * -qt-freetype ....... Use the libfreetype bundled with Qt.  * -system-freetype ... Use the libfreetype provided by the system.  + -angle ............. Use the ANGLE implementation of OpenGL ES 2.0.     -angle-d3d11 ....... Use the Direct3D 11-based ANGLE implementation of                          OpenGL ES 2.0.     -no-angle .......... Do not use ANGLE.                          See http://code.google.com/p/angleproject/ Qt for Windows only:     -no-vcproj ......... Do not generate VC++ .vcproj files.  * -vcproj ............ Generate VC++ .vcproj files, only if platform                          "win32-msvc.net".     -no-incredibuild-xge Do not add IncrediBuild XGE distribution commands to                          custom build steps.  + -incredibuild-xge .. Add IncrediBuild XGE distribution commands to custom                          build steps. This will distribute MOC and UIC steps,                          and other custom buildsteps which are added to the                          INCREDIBUILD_XGE variable.                          (The IncrediBuild distribution commands are only added                          to Visual Studio projects)     -no-plugin-manifests Do not embed manifests in plugins.  * -plugin-manifests .. Embed manifests in plugins.     -no-qmake .......... Do not compile qmake.  * -qmake ............. Compile qmake.  * -process ........... Generate only top-level Makefile.     -fully-process ..... Generate Makefiles/Project files for the entire Qt                          tree.     -dont-process ...... Do not generate Makefiles/Project files.     -no-rtti ........... Do not compile runtime type information.  * -rtti .............. Compile runtime type information.     -no-strip .......... Do not strip libraries and executables of debug info                          when installing.  * -strip ............. Strip libraries and executables of debug info when                          installing.     -no-sse2 ........... Do not compile with use of SSE2 instructions.  + -sse2 .............. Compile with use of SSE2 instructions.     -no-sse3 ........... Do not compile with use of SSE3 instructions.  + -sse3 .............. Compile with use of SSE3 instructions.     -no-ssse3 .......... Do not compile with use of SSSE3 instructions.  + -ssse3 ............. Compile with use of SSSE3 instructions.     -no-sse4.1 ......... Do not compile with use of SSE4.1 instructions.  + -sse4.1 ............ Compile with use of SSE4.1 instructions.     -no-sse4.2 ......... Do not compile with use of SSE4.2 instructions.  + -sse4.2 ............ Compile with use of SSE4.2 instructions.     -no-avx ............ Do not compile with use of AVX instructions.  + -avx ............... Compile with use of AVX instructions.     -no-avx2 ........... Do not compile with use of AVX2 instructions.  + -avx2 .............. Compile with use of AVX2 instructions.     -no-openssl ........ Do not compile support for OpenSSL.  + -openssl ........... Enable run-time OpenSSL support.     -openssl-linked .... Enable linked OpenSSL support.     -no-dbus ........... Do not compile in D-Bus support.  + -dbus .............. Compile in D-Bus support and load libdbus-1                          dynamically.     -dbus-linked ....... Compile in D-Bus support and link to libdbus-1.     -no-audio-backend .. Do not compile in the platform audio backend into                          Qt Multimedia.  + -audio-backend ..... Compile in the platform audio backend into Qt                          Multimedia.     -no-qml-debug ...... Do not build the in-process QML debugging support.  * -qml-debug ......... Build the in-process QML debugging support.  * -no-directwrite .... Do not build support for DirectWrite font rendering.     -directwrite ....... Build support for DirectWrite font rendering                          (experimental, requires DirectWrite availability on                          target systems, e.g. Windows Vista with Platform                          Update, Windows 7, etc.)     -no-style-<style> .. Disable <style> entirely.     -qt-style-<style> .. Enable <style> in the Qt Library.                          Available styles:  * windows  + windowsxp  + windowsvista  * fusion                            windowsce                            windowsmobile     -no-native-gestures Do not use native gestures on Windows 7.  * -native-gestures ... Use native gestures on Windows 7.  * -no-mp ............. Do not use multiple processors for compiling with MSVC     -mp ................ Use multiple processors for compiling with MSVC (-MP).     -loadconfig <config> Run configure with the parameters from file configure_                          <config>.cache.     -saveconfig <config> Run configure and save the parameters in file                          configure_<config>.cache.     -redo .............. Run configure with the same parameters as last time. Qt for Windows CE only:     -no-iwmmxt ......... Do not compile with use of IWMMXT instructions.  + -iwmmxt ............ Do compile with use of IWMMXT instructions. (Qt for                          Windows CE on Arm only)  * -no-crt ............ Do not add the C runtime to default deployment rules.     -qt-crt ............ Qt identifies C runtime during project generation.     -crt <path> ........ Specify path to C runtime used for project generation.     -no-cetest ......... Do not compile Windows CE remote test application.  + -cetest ............ Compile Windows CE remote test application.     -signature <file> .. Use <file> for signing the target project. 如要重新 confgure,先运行 nmake confclean 4.3.4 运行 nmake(VS2010)进行编译 4.3.5 运行 nmake install 进行安装 4.3.6 在 VS2010 中配置 Qt,选择编译好的静态...