qwt介绍
QWT,全称是Qt Widgets for Technical Applications,是一个基于LGPL版权协议的开源项目, 可生成各种统计图。
它为具有技术专业背景的程序提供GUI组件和一组实用类,其目标是以基于2D方式的窗体部件来显示数据, 数据源以数值,数组或一组浮点数等方式提供, 输出方式可以是Curves(曲线),Slider(滚动条),Dials(圆盘),Compasses(仪表盘)等等。该工具库基于Qt开发,所以也继承了Qt的跨平台特性。
我的例子代码下载 https://download.csdn.net/download/hu626626/13270841
我用的 qwt 6.1.4 , QT 5.13.1 , VS2017。
qwt下载
https://sourceforge.net/projects/qwt/files/
qwt用户指南
编译安装
qwt的源码解压后,是这个样子的。
designer 目录是 Qwt 插件的源码,doc 目录是帮助文档,example 目录是 Qwt 例子的源码,src 目录是 Qwt 的源码,textengines 目录是数学指标语言的文本驱动引擎代码
先看下 qwtconfig.pri 。
################################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
QWT_VER_MAJ = 6
QWT_VER_MIN = 1
QWT_VER_PAT = 4
QWT_VERSION = $${QWT_VER_MAJ}.$${QWT_VER_MIN}.$${QWT_VER_PAT}
######################################################################
# Install paths
######################################################################
# 这个是安装的配置,比如安装路径等
# 从这里我们可以看到,
# qwt默认安装到/usr/local下,
# 默认建立一下几个主要目录doc, include, lib
# 次要主目录/plugins/designer, /features
#
QWT_INSTALL_PREFIX = $$[QT_INSTALL_PREFIX]
unix {
QWT_INSTALL_PREFIX = /usr/local/qwt-$$QWT_VERSION
# QWT_INSTALL_PREFIX = /usr/local/qwt-$$QWT_VERSION-qt-$$QT_VERSION
}
win32 {
QWT_INSTALL_PREFIX = C:/Qwt-$$QWT_VERSION
# QWT_INSTALL_PREFIX = C:/Qwt-$$QWT_VERSION-qt-$$QT_VERSION
}
QWT_INSTALL_DOCS = $${QWT_INSTALL_PREFIX}/doc
QWT_INSTALL_HEADERS = $${QWT_INSTALL_PREFIX}/include
QWT_INSTALL_LIBS = $${QWT_INSTALL_PREFIX}/lib
######################################################################
# Designer plugin
# creator/designer load designer plugins from certain default
# directories ( f.e the path below QT_INSTALL_PREFIX ) and the
# directories listed in the QT_PLUGIN_PATH environment variable.
# When using the path below QWT_INSTALL_PREFIX you need to
# add $${QWT_INSTALL_PREFIX}/plugins to QT_PLUGIN_PATH in the
# runtime environment of designer/creator.
######################################################################
QWT_INSTALL_PLUGINS = $${QWT_INSTALL_PREFIX}/plugins/designer
# linux distributors often organize the Qt installation
# their way and QT_INSTALL_PREFIX doesn't offer a good
# path. Also QT_INSTALL_PREFIX is only one of the default
# search paths of the designer - not the Qt creator
#QWT_INSTALL_PLUGINS = $$[QT_INSTALL_PREFIX]/plugins/designer
######################################################################
# Features
# When building a Qwt application with qmake you might want to load
# the compiler/linker flags, that are required to build a Qwt application
# from qwt.prf. Therefore all you need to do is to add "CONFIG += qwt"
# to your project file and take care, that qwt.prf can be found by qmake.
# ( see http://doc.trolltech.com/4.7/qmake-advanced-usage.html#adding-new-configuration-features )
# I recommend not to install the Qwt features together with the
# Qt features, because you will have to reinstall the Qwt features,
# with every Qt upgrade.
######################################################################
QWT_INSTALL_FEATURES = $${QWT_INSTALL_PREFIX}/features
# QWT_INSTALL_FEATURES = $$[QT_INSTALL_PREFIX]/features
# 下面这些选项很重要了, 因为您的qt如果是自编译的,
# 那么很多第三方库,或者支持库是没有被编译的
# 而且尤其在arm上我们编译qwt时候, 编译那么多无用的支持是没用的
# QWT_CONFIG可以为动态的增减我们需要的库支持
######################################################################
# Build the static/shared libraries.
# If QwtDll is enabled, a shared library is built, otherwise
# it will be a static library.
######################################################################
# 选择是编译成静态库还是动态库
QWT_CONFIG += QwtDll
######################################################################
# QwtPlot enables all classes, that are needed to use the QwtPlot
# widget.
######################################################################
QWT_CONFIG += QwtPlot
######################################################################
# QwtWidgets enables all classes, that are needed to use the all other
# widgets (sliders, dials, ...), beside QwtPlot.
######################################################################
QWT_CONFIG += QwtWidgets
######################################################################
# If you want to display svg images on the plot canvas, or
# export a plot to a SVG document
######################################################################
QWT_CONFIG += QwtSvg
######################################################################
# If you want to use a OpenGL plot canvas
######################################################################
# 是否支持QwtOpenGL, 依赖于QtOpenGL库
# 不是必选,
# 如果您不需要QwtOpenGL支持, 可以注释
# 如果Qt库中没编译QtOpenGL, 必须注释, 否则编译出错, 因为找不到依赖的QtOpenGL库
# 提示的错误类似与,找不到qgl.h等有文件,因为我有QtOpenGL,所以没有注释
QWT_CONFIG += QwtOpenGL
######################################################################
# You can use the MathML renderer of the Qt solutions package to
# enable MathML support in Qwt. Because of license implications
# the ( modified ) code of the MML Widget solution is included and
# linked together with the QwtMathMLTextEngine into an own library.
# To use it you will have to add "CONFIG += qwtmathml"
# to your qmake project file.
######################################################################
# 是否支持QwtMathMl, 是Qwt统计数据的数学库支持
#QWT_CONFIG += QwtMathML
######################################################################
# If you want to build the Qwt designer plugin,
# enable the line below.
# Otherwise you have to build it from the designer directory.
######################################################################
# 是否支持QwtDesigner,
QWT_CONFIG += QwtDesigner
######################################################################
# Compile all Qwt classes into the designer plugin instead
# of linking it against the shared Qwt library. Has no effect
# when QwtDesigner or QwtDll are not both enabled.
#
# On systems where rpath is supported ( all Unixoids ) the
# location of the installed Qwt library is compiled into the plugin,
# but on Windows it might be easier to have a self contained
# plugin to avoid any hassle with configuring the runtime
# environment of the designer/creator.
######################################################################
win32 {
QWT_CONFIG += QwtDesignerSelfContained
}
######################################################################
# If you want to auto build the examples, enable the line below
# Otherwise you have to build them from the examples directory.
######################################################################
# 是否编译示例程序
# qwt默认不编译示例程序,
# 如果您想编译示例, 请取消注释
#QWT_CONFIG += QwtExamples
######################################################################
# The playground is primarily intended for the Qwt development
# to explore and test new features. Nevertheless you might find
# ideas or code snippets that help for application development
# If you want to auto build the applications in playground, enable
# the line below.
# Otherwise you have to build them from the playground directory.
######################################################################
#QWT_CONFIG += QwtPlayground
######################################################################
# When Qt has been built as framework qmake wants
# to link frameworks instead of regular libs
######################################################################
macx:!static:CONFIG(qt_framework, qt_framework|qt_no_framework) {
QWT_CONFIG += QwtFramework
}
######################################################################
# Create and install pc files for pkg-config
# See http://www.freedesktop.org/wiki/Software/pkg-config/
######################################################################
unix {
#QWT_CONFIG += QwtPkgConfig
}
编译的话很简单,直接 QT 打开 qwt.pro 就打开项目了。
安卓环境如下
windows 环境是 msvc 2017 32位。
编译时出现问题
有时会出现报错,编译失败。忘记什么原因,忘记截图,但是解决方法如下。
解决方法:打开 qwtbuild.pri ,找到
CONFIG += debug_and_release
注释掉、编译就会成功。
编译完成后。来到 build-qwt-Desktop_Qt_5_13_1_MSVC2017_32bit-Release\designer\plugins\designer 下,即可看到
将这三个拷贝到QT安装目录下 Qt\Tools\QtCreator\bin\plugins\designer
以防万一,因为我使用windows开发,所以我还拷贝到了 Qt\5.13.1\msvc2017\plugins\designer
这样开发界面就会出现
就可以拖拽控件了
安卓使用qwt配置
在 build-qwt-Android_for_armeabi_v7a_Clang_Qt_5_13_1_for_Android_ARMv7-Release\lib 下有 libqwt.so
将其拷贝到 Qt\5.13.1\android_armv7\lib
将qwt.prf 拷贝到 Qt\5.13.1\android_armv7\lib目录中(你安装的QT目录中)
把 build-qwt-Android_for_armeabi_v7a_Clang_Qt_5_13_1_for_Android_ARMv7-Release\android-build\usr\local\qwt-6.1.4\include 中所有文件拷贝,之后在 Qt\5.13.1\android_armv7\include 中新建一个文件夹QWT,把刚才拷贝的文件放进去
在自己工程的 pro 里加入
DEFINES += QWT_DLL
CONFIG += qwt
INCLUDEPATH += C:/Qt/Qt5.6.3/5.6.3/android_armv7/include/QWT
DEPENDPATH += C:/Qt/Qt5.6.3/5.6.3/android_armv7/include/QWT
include (C:/Qt/Qt5.6.3/5.6.3/android_armv7/lib/qwt.prf)
windows使用qwt配置
将 build-qwt-Android_for_armeabi_v7a_Clang_Qt_5_13_1_for_Android_ARMv7-Release\android-build\usr\local\qwt-6.1.4\include 下的所有头文件拷到新建 include 下 , build-qwt-Desktop_Qt_5_13_1_MSVC2017_32bit-Release\lib 下的所有dll lib 都拷到新建 lib 下,自建文件夹如下。
在工程的 pro 中,添加 include 路径,因为编译的时候需要 opengl ,所以将 opengl 也加进去。
还要添加 lib 库,
添加的是 windows 动态库。因为需要 opengl 的原因,将 opengl 动态库也加进去了。
编译时出现问题
1.会提示找不到 gpl.h ,
解决方法:上面图有,直接将 opengl 路径加上去了
2.会提示找不到 OpenGL 的 dll ,
解决方法:上面图有,直接将 opengl 库加上去了
2.会提示各种未定义的 qwt 函数,不应使用 qwt 界面啊什么的
解决方法:一般都是缺少 qwt 头文件啊, qwt 库啊。检查路径是否对。