introduce
Recently, Qt has open-sourced the QtCharts graphical widget. Now we can compile and configure our own development environment, and use QtCharts to design various histograms and discounted charts for free. There are some examples compiled for MinGW+QtCreator on the Internet and finally used in QtCreator. For Qt+VS users, there is still relatively little information on how to compile MSVC+QTCharts and configure QtCharts. Therefore, after asking a netizen for advice, the author decided to write this blog post as a record.
Download QtCharts source code and Perl compiler
QtCharts download address (GitHub): https://github.com/qtproject/qtcharts
I provide the downloaded QtChart and Perl compiler: http://pan.baidu.com/s/1qXe10KW
Note: Before compiling QtCharts, you need to first Install Perl and configure it well, otherwise there will be an error when compiling QtCharts! QtCreator is also required.
Perl installation
You can choose the default path to install Perl, or you can specify the path you need. How to install and configure, Baidu experience is very detailed, please check the link below: http://jingyan.baidu.com/article/9f7e7ec0b798ae6f281554e9.html?st=2&os=0&bd_page_type=1&net_type=1
Note: After configuring the environment variables, you need to log out or reboot the system.
Compile QtCharts
- Unzip QtCharts, and open the qtcharts.pro file with QtCreator.
- build project
- deployment project
- deployment complete
Install QtCharts help documentation
- Make parameter input: docs, then redeploy the project.
- Copy the files in the directory E:\CPlusPlusLib\build-qtcharts-unknown-Release\doc to the directory: C:\Qt\Qt5.5.1\Docs\Qt-5.5.
- Restart QtCreator and search for QtCharts in the help.
Install QtCharts Eamples
- Copy the charts file in the source code directory: E:\CPlusPlusLib\qtcharts\examples to the Qt library directory C:\Qt\Qt5.5.1\Examples\Qt-5.5.
- Modify the examples.pro file in the Qt\Qt5.5.1\Examples\Qt-5.5 folder.
- Restart QtCreator, enter charts in the example, and view the example.
Configure QtCharts in VS2013
- Open VS2013 to create a new Qt project.
- Create a new QtChart property sheet, and modify the VC++ directory and additional dependencies as follows
- Add the following code in the source file testqtcharts.cpp
QLineSeries *series = new QLineSeries();
series->append(0, 6);
series->append(2, 4);
series->append(3, 8);
series->append(7, 4);
series->append(10, 5);
*series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
QChart *chart = new QChart();
chart->legend()->hide();
chart->addSeries(series);
chart->createDefaultAxes();
chart->setTitle("Simple line chart example");
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
setCentralWidget(chartView);
- Compile and run the results
Program engineering (code + UI file + property sheet) sharing
Baidu cloud download link: http://pan.baidu.com/s/1sk8l38D