Qwt安装以及使用 QPlugin调用 QT与VS2017环境配置
创始人
2024-04-01 02:09:50
0

1.Qwt安装以及使用

大佬文章地址:

安装和使用

Qwt、QChart、QCustomPlot使用_mahuifa的博客-CSDN博客_qcustomplot qwt

 常用接口

Qt之Qwt曲线绘制_&a_shu的博客-CSDN博客_qt绘制函数曲线

#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);//初始化ui->qwtPlot->setTitle("Qwt Demo");ui->qwtPlot->setCanvasBackground(Qt::gray);ui->qwtPlot->insertLegend(new QwtLegend(),QwtPlot::RightLegend);QwtPlotZoomer *zoomer = new QwtPlotZoomer( ui->qwtPlot->canvas() );zoomer->setRubberBandPen( QColor( Qt::blue ) );zoomer->setTrackerPen( QColor( Qt::black ) );zoomer->setMousePattern(QwtEventPattern::MouseSelect2,Qt::RightButton, Qt::ControlModifier );zoomer->setMousePattern(QwtEventPattern::MouseSelect3,Qt::RightButton );//QwtPlotMagnifier *magnifier = new QwtPlotMagnifier(ui->qwtPlot->canvas() );                 //默认的滑轮及右键缩放功能  图形的整体缩放//magnifier->setMouseButton(Qt::LeftButton);     //设置哪个按钮与滑轮为缩放画布  如果不设置(注册掉当前行)按钮默认为滑轮以及右键为缩放//实时显示坐标数据d_picker = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft,QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,ui->qwtPlot->canvas() );d_picker->setStateMachine( new QwtPickerDragPointMachine() );d_picker->setRubberBandPen( QColor( Qt::green ) );d_picker->setRubberBand( QwtPicker::CrossRubberBand );d_picker->setTrackerPen( QColor( Qt::white ));QwtPlotGrid *grid = new QwtPlotGrid();grid->enableX( true );//设置网格线grid->enableY( true );grid->setMajorPen( Qt::black, 0, Qt::DotLine );grid->attach(ui->qwtPlot);curve = new QwtPlotCurve();curve->setTitle("曲线0");curve->setPen(Qt::yellow,1);//加载数据QVector x;QVectory;for (int i=1;i<2000;i++) {x.append(i);y.append(i/10.0);}curve->setSamples(x,y);curve->attach(ui->qwtPlot);ui->qwtPlot->replot();
}MainWindow::~MainWindow()
{delete ui;
}

 结果如图

 

2.QPlugin调用以及插件与主程序之间通信

对于主工程来说,需要定一个插件的接口:

  1. 使用 Q_DECLARE_INTERFACE() 宏告诉 Qt meta-object 系统这个接口;
  2. 使用 QPluginLoader 来加载插件;
  3. 使用 qobject_cast() 进行插件造型,判断插件实现了哪个接口;

对于插件工程来说,需要实现一个接口:

  1. 定义一个继承 QObject 和 接口的插件;
  2. 使用 Q_INTERFACES() 声明使用的接口类型;
  3. 使用 the Q_PLUGIN_METADATA() 宏导出元信息;
  4. 使用合适的 *.pro 文件构建工程

经典博客:

Qt 5 杂谈:使用信号槽机制进行插件与主程序的通信_野生指针的博客-CSDN博客 具体实现代码github上有源码,可以自己研究。

Qt插件开发总结--插件的创建及使用_贝勒里恩的博客-CSDN博客_qt插件

自我实现:

 接口类为customwidget.h中的QDesignerCustomWidgetInterface

#ifndef CUSTOMWIDGET_H
#define CUSTOMWIDGET_H#include 
#include 
#include QT_BEGIN_NAMESPACEclass QWidget;
class QDesignerFormEditorInterface;
class QDesignerCustomWidgetInterface
{
public:virtual ~QDesignerCustomWidgetInterface() {}virtual QString name() const = 0;virtual QString group() const = 0;virtual QString toolTip() const = 0;virtual QString whatsThis() const = 0;virtual QString includeFile() const = 0;virtual QIcon icon() const = 0;virtual bool isContainer() const = 0;virtual QWidget *createWidget(QWidget *parent) = 0;virtual bool isInitialized() const { return false; }virtual void initialize(QDesignerFormEditorInterface *core) { Q_UNUSED(core); }virtual QString domXml() const{return QString::fromUtf8("").arg(name()).arg(name().toLower());}virtual QString codeTemplate() const { return QString(); }
};
#define QDesignerCustomWidgetInterface_iid "org.qt-project.QDesignerCustomWidgetInterface"
Q_DECLARE_INTERFACE(QDesignerCustomWidgetInterface, QDesignerCustomWidgetInterface_iid)QT_END_NAMESPACE#endif // CUSTOMWIDGET_H

加载插件

#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);loadPlugin();w = m_pInterface->createWidget(ui->centralWidget);setWindowTitle(tr("世界时钟"));ui->verticalLayout->addWidget(w);
}MainWindow::~MainWindow()
{delete ui;
}bool MainWindow::loadPlugin()
{QDir pluginsDir(qApp->applicationDirPath());#if defined (Q_OS_WIN)/*if(pluginsDir.dirName().toLower() == "debug" ||pluginsDir.dirName().toLower() == "release") {//pluginsDir.cdUp();  //pluginsDir: "../build-xxx-debug"//pluginsDir.cdUp();  //pluginsDir: "../"}*/#elif defined(Q_OS_MAC)if(pluginsDir.dirName() == "MacIOS) {pluginsDir.cdUp();pluginsDir.cdUp();pluginsDir.cdUp();}#endifpluginsDir.cd("plugins");foreach(QString fileName, pluginsDir.entryList(QDir::Files)) {QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));QObject *plugin = pluginLoader.instance();//qDebug()<<__FUNCTION__<(plugin);//检验接口类if(m_pInterface) {return true;}}}return false;
}

调用的插件(QT 自带插件示例 worldtimeclock)路径

效果:

3.QT与VS2017环境配置

 Qt5.11.1安装与VS2017配置_GJXAIOU的博客-CSDN博客_qt vs2017

vs2017+Qt 无法打开ui文件_九三三的博客-CSDN博客_vs2017无法打开ui文件

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...
有效的括号 一、题目 给定一个只包括 '(',')','{','}'...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...