VS2017+QT5.12+qcustomplot

好了,研究生生活开始了,VS+QT环境配了半天,运行QCustomPlot用弄了半天,都想放弃了,结果柳暗花明。这件事告诉我,不能再像以前那样,遇到一些困难就放弃。

首先说,VS配置QT,请参考这篇博客:https://blog.csdn.net/qq_33154343/article/details/78587699

对,它是可以的。

然后,开始使用QCustomPlot,请参考:https://blog.csdn.net/iloveqt5/article/details/21298037

亲测上面的代码可用,但是我的还是出现了一些错误

附上我的代码:

#include "mainWindows.h"
#include"qcustomplot.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	mainWindows w;
	w.show();
	QCustomPlot *customPlot = new QCustomPlot;
	QVector<double>x(101), y(101);
	for (int i = 0;i < 101;++i)
	{
		x[i] = i / 50.0 - 1;
		y[i] = x[i] * x[i];
	}
	customPlot->addGraph();
	customPlot->graph(0)->setData(x, y);
	customPlot->xAxis->setLabel("x");
	customPlot->yAxis->setLabel("y");
	customPlot->xAxis->setRange(-1, 1);
	customPlot->yAxis->setRange(0, 1);
	customPlot->replot();
	customPlot->show();
 
	return a.exec();
}

在这里插入图片描述
在这里插入图片描述
当然配置之后,会出现一些问题。

比如:

1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: virtual __thiscall QPrinter::~QPrinter(void)" (__imp_??1QPrinter@@UAE@XZ),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,bool,int,int,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@_NHH00@Z) 中被引用 1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QPrinter::setPaperSize(class QSizeF const &,enum QPrinter::Unit)" (__imp_?setPaperSize@QPrinter@@QAEXABVQSizeF@@W4Unit@1@@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,bool,int,int,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@_NHH00@Z) 中被引用 1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: class QPrintEngine * __thiscall QPrinter::printEngine(void)const " (__imp_?printEngine@QPrinter@@QBEPAVQPrintEngine@@XZ),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,bool,int,int,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@_NHH00@Z) 中被引用 1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QPrinter::setColorMode(enum QPrinter::ColorMode)" (__imp_?setColorMode@QPrinter@@QAEXW4ColorMode@1@@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,bool,int,int,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@_NHH00@Z) 中被引用 1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QPrinter::setFullPage(bool)" (__imp_?setFullPage@QPrinter@@QAEX_N@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,bool,int,int,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@_NHH00@Z) 中被引用 1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QPrinter::setOutputFormat(enum QPrinter::OutputFormat)" (__imp_?setOutputFormat@QPrinter@@QAEXW4OutputFormat@1@@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,bool,int,int,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@_NHH00@Z) 中被引用 1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QPrinter::setOutputFileName(class QString const &)" (__imp_?setOutputFileName@QPrinter@@QAEXABVQString@@@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,bool,int,int,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@_NHH00@Z) 中被引用 1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QPrinter::QPrinter(enum QPrinter::PrinterMode)" (__imp_??0QPrinter@@QAE@W4PrinterMode@0@@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,bool,int,int,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@_NHH00@Z) 中被引用
解决方法:

“项目属性 -> 配置属性 -> 链接器 -> 输入 -> 附加依赖项”里面添加“Qt5PrintSupportd.lib”;

参考:https://blog.csdn.net/ch2065/article/details/28446959

2.vs无法打开源文件问题

请参考:https://blog.csdn.net/qq_28779503/article/details/70599653

依次点击“项目——配置属性——C/C++——常规”,在“附加包含目录”中加入.h文件所在的文件夹路径
在这里插入图片描述

3.新建.pro文件

右键项目-》Create Basic .pro File.一路确认就好。

也许还是有很多问题,一步一步来。

版权声明:本文为CSDN博主「xueleiok」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xueleiok/article/details/80912184

  • 4
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值