-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
44 lines (32 loc) · 1008 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <thread>
#include <QtCharts/QVXYModelMapper>
#include <cmath>
#include "mydatamodel.h"
void point_generator_proc(MyDataModel* model)
{
for(double t=0 ; ; t+=1)
{
double y = (1 + sin(t/10.0)) / 2.0;
model->handleNewPoint(QPointF(t, y));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
auto context = engine.rootContext();
auto myDataModel = new MyDataModel();
auto mapper = new QtCharts::QVXYModelMapper();
mapper->setModel(myDataModel);
mapper->setXColumn(0);
mapper->setYColumn(1);
std::thread point_generator_thread(point_generator_proc, myDataModel);
point_generator_thread.detach();
context->setContextProperty("mapper", mapper);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}