加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mainwindow.cpp 21.18 KB
一键复制 编辑 原始数据 按行查看 历史
1ndustry 提交于 2022-09-05 10:16 . fitst
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QtNetwork>
#include<QMenu>
#pragma comment (lib, "thostmduserapi_se.lib")
#pragma comment (lib, "thosttraderapi_se.lib")
#include <QSqlError>
#include "MdSpi.h"
#include<qsqlquery.h>
CThostFtdcMdApi* g_pMdUserApi = nullptr;
CThostFtdcTraderApi* pUserApi = nullptr;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("127.0.0.1");
db.setPort(3306);
db.setDatabaseName("2");
db.setUserName("root");
db.setPassword("password");
if(db.open()){
qDebug()<<"111!";
}
QStringList tables = db.tables();
foreach(QString table, tables)
qDebug()<<table;
manager = new QNetworkAccessManager(this);
getSinaData();
//........行情表.............//
ui->tableHQ_2->setColumnCount(11);
QStringList headerHQ;
headerHQ.append(QString::fromLocal8Bit("合约代码"));
headerHQ.append(QString::fromLocal8Bit("更新时间"));
headerHQ.append(QString::fromLocal8Bit("最新价"));
headerHQ.append(QString::fromLocal8Bit("买一价"));
headerHQ.append(QString::fromLocal8Bit("买一量"));
headerHQ.append(QString::fromLocal8Bit("卖一价"));
headerHQ.append(QString::fromLocal8Bit("卖一量"));
headerHQ.append(QString::fromLocal8Bit("涨幅"));
headerHQ.append(QString::fromLocal8Bit("成交量"));
headerHQ.append(QString::fromLocal8Bit("涨停价"));
headerHQ.append(QString::fromLocal8Bit("跌停价"));
ui->tableHQ_2->setHorizontalHeaderLabels(headerHQ);
ui->tableHQ_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableHQ_2->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableHQ_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
//........委托表.............//
ui->tableWT_2->setColumnCount(9);
QStringList headerWT;
headerWT.append(QString::fromLocal8Bit("委托时间"));
headerWT.append(QString::fromLocal8Bit("合约代码"));
headerWT.append(QString::fromLocal8Bit("买卖"));
headerWT.append(QString::fromLocal8Bit("开平"));
headerWT.append(QString::fromLocal8Bit("数量"));
headerWT.append(QString::fromLocal8Bit("价格"));
headerWT.append(QString::fromLocal8Bit("状态"));
headerWT.append(QString::fromLocal8Bit("委托号"));
headerWT.append(QString::fromLocal8Bit("交易所"));
ui->tableWT_2->setHorizontalHeaderLabels(headerWT);
ui->tableWT_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableWT_2->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWT_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
//........成交表.............//
ui->tableCJ_2->setColumnCount(8);
QStringList headerCJ;
headerCJ.append(QString::fromLocal8Bit("成交时间"));
headerCJ.append(QString::fromLocal8Bit("合约代码"));
headerCJ.append(QString::fromLocal8Bit("买卖"));
headerCJ.append(QString::fromLocal8Bit("开平"));
headerCJ.append(QString::fromLocal8Bit("数量"));
headerCJ.append(QString::fromLocal8Bit("价格"));
headerCJ.append(QString::fromLocal8Bit("委托号"));
headerCJ.append(QString::fromLocal8Bit("交易所"));
ui->tableCJ_2->setHorizontalHeaderLabels(headerCJ);
ui->tableCJ_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableCJ_2->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableCJ_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
//........持仓表.............//
ui->tableCC_2->setColumnCount(4);
QStringList headerCC;
headerCC.append(QString::fromLocal8Bit("合约代码"));
headerCC.append(QString::fromLocal8Bit("持仓类型"));
headerCC.append(QString::fromLocal8Bit("持仓数量"));
headerCC.append(QString::fromLocal8Bit("持仓成本"));
ui->tableCC_2->setHorizontalHeaderLabels(headerCC);
ui->tableCC_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableCC_2->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableCC_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
//........资金表.............//
ui->tableZJ_2->setColumnCount(5);
QStringList headerZJ;
headerZJ.append(QString::fromLocal8Bit("账号"));
headerZJ.append(QString::fromLocal8Bit("总权益"));
headerZJ.append(QString::fromLocal8Bit("占用保证金"));
headerZJ.append(QString::fromLocal8Bit("可用资金"));
headerZJ.append(QString::fromLocal8Bit("风险度"));
ui->tableZJ_2->setHorizontalHeaderLabels(headerZJ);
ui->tableZJ_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableZJ_2->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableZJ_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
//........合约表.............//
ui->tableHY->setColumnCount(4);
QStringList headerHY;
headerHY.append(QString::fromLocal8Bit("合约代码"));
headerHY.append(QString::fromLocal8Bit("合约名称"));
headerHY.append(QString::fromLocal8Bit("合约乘数"));
headerHY.append(QString::fromLocal8Bit("合约点数"));
ui->tableHY->setHorizontalHeaderLabels(headerHY);
ui->tableHY->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableHY->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableHY->setEditTriggers(QAbstractItemView::NoEditTriggers);
/////////////////////////////////////////////////////////////////////
ui->lineEdit_12->setText("tcp://180.168.146.187:10212");
ui->lineEdit_13->setText("tcp://180.168.146.187:10202");
ui->lineEdit_14->setText("9999");
ui->lineEdit_15->setText("204925");
ui->lineEdit_16->setText("***************");
ui->radioButton_7->setChecked(true);
ui->radioButtonsj->setChecked(true);
g_pMdUserApi = CThostFtdcMdApi::CreateFtdcMdApi(); // 创建行情实例
MdSpi* pMdUserSpi = new MdSpi(); // 创建行情回调实例
g_pMdUserApi->RegisterSpi(pMdUserSpi);
// 注册事件类
g_pMdUserApi->RegisterFront((char*)"tcp://180.168.146.187:10131"); // 设置行情前置地址
g_pMdUserApi->Init(); // 连接运行
//g_pMdUserApi->Join();
pUserApi = CThostFtdcTraderApi::CreateFtdcTraderApi();
ptdUserSpi = new CTraderSpi();
pUserApi->RegisterSpi(ptdUserSpi);
pUserApi->RegisterFront((char*)"tcp://180.168.146.187:10130");
pUserApi->SubscribePrivateTopic(THOST_TERT_QUICK);
pUserApi->SubscribePublicTopic(THOST_TERT_QUICK);
pUserApi->Init();
connect((const QObject *)pMdUserSpi,SIGNAL(sendData(QString)),this,SLOT(ReceiveHQ(QString)));
connect((const QObject *)ptdUserSpi,SIGNAL(sendDataCJ(QString)),this,SLOT(ReceiveCJ(QString)));
connect((const QObject *)ptdUserSpi,SIGNAL(sendDataWT(QString)),this,SLOT(ReceiveWT(QString)));
connect((const QObject *)ptdUserSpi,SIGNAL(sendDataHY(QString)),this,SLOT(ReceiveHY(QString)));
connect((const QObject *)ptdUserSpi,SIGNAL(sendDataCC(QString)),this,SLOT(ReceiveCC(QString)));
connect((const QObject *)ptdUserSpi,SIGNAL(sendDataZJ(QString)),this,SLOT(ReceiveZJ(QString)));
QObject::connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedSlot(QNetworkReply*)));
ui->tableHQ_2->horizontalHeader()->setVisible(true);
ui->tableWT_2->horizontalHeader()->setVisible(true);
ui->tableZJ_2->horizontalHeader()->setVisible(true);
ui->tableCJ_2->horizontalHeader()->setVisible(true);
ui->tableCC_2->horizontalHeader()->setVisible(true);
ui->tableHY->horizontalHeader()->setVisible(true);
ui->lineEditDm->setText("nr2302");
ui->lineEditSl->setText("1");
///////////////////////右键菜单
ui->tableWT_2->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableWT_2,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(OnWTmenu(const QPoint&)));
connect(ui->actioncd,SIGNAL(triggered()),this,SLOT(ct()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_5_clicked()
{
this->close();
}
void MainWindow::ReceiveHQ(QString Tick)
{
QStringList strlist = Tick.split(",");
//qDebug()<<strlist<<endl;
if(strlist.at(0)==ui->lineEditDm->text()){
ui->labelask->setText(strlist.at(5));
ui->labellast->setText(strlist.at(2));
ui->labelbid->setText(strlist.at(3));
ui->labelup->setText(strlist.at(9));
ui->labeldown->setText(strlist.at(10));
}
for(int i =0;i<ui->tableHQ_2->rowCount();i++)
{
if(ui->tableHQ_2->item(i,0)->text()==strlist.at(0)){
ui->tableHQ_2->setItem(i,0,new QTableWidgetItem(strlist.at(0)));
ui->tableHQ_2->setItem(i,1,new QTableWidgetItem(strlist.at(1)));
ui->tableHQ_2->setItem(i,2,new QTableWidgetItem(strlist.at(2)));
// QSqlQuery result = db.exec(" select * from ctp.hq");
// QString userIdValue;
// QString pswValue;
// QString nameValue;
// //qDebug()<<"开始!";
// while(result.next()){
// userIdValue=result.value("HQ").toString();
// nameValue=result.value("GXSJ").toString();
// pswValue=result.value("ZXJ").toString();
// qDebug()<<userIdValue<<"1!";
// qDebug()<<nameValue<<"2!";
// qDebug()<<pswValue<<"3!";
// }/*while(result.next())*/
QSqlQuery query(db);
query.prepare("INSERT INTO ctp.hq (HQ, GXSJ, ZXJ) "
"VALUES (:id, :forename, :surname)");
query.bindValue(0, strlist.at(0));
query.bindValue(1, strlist.at(1));
query.bindValue(2, strlist.at(2));
query.exec();
ui->tableHQ_2->setItem(i,3,new QTableWidgetItem(strlist.at(3)));
ui->tableHQ_2->setItem(i,4,new QTableWidgetItem(strlist.at(4)));
ui->tableHQ_2->setItem(i,5,new QTableWidgetItem(strlist.at(5)));
ui->tableHQ_2->setItem(i,6,new QTableWidgetItem(strlist.at(6)));
ui->tableHQ_2->setItem(i,7,new QTableWidgetItem(strlist.at(7)));
ui->tableHQ_2->setItem(i,8,new QTableWidgetItem(strlist.at(8)));
ui->tableHQ_2->setItem(i,9,new QTableWidgetItem(strlist.at(9)));
ui->tableHQ_2->setItem(i,10,new QTableWidgetItem(strlist.at(10)));
return;
}
}
int row=ui->tableHQ_2->rowCount();
ui->tableHQ_2->insertRow(row);
ui->tableHQ_2->setItem(row,0,new QTableWidgetItem(strlist.at(0)));
ui->tableHQ_2->setItem(row,1,new QTableWidgetItem(strlist.at(1)));
ui->tableHQ_2->setItem(row,2,new QTableWidgetItem(strlist.at(2)));
ui->tableHQ_2->setItem(row,3,new QTableWidgetItem(strlist.at(3)));
ui->tableHQ_2->setItem(row,4,new QTableWidgetItem(strlist.at(4)));
ui->tableHQ_2->setItem(row,5,new QTableWidgetItem(strlist.at(5)));
ui->tableHQ_2->setItem(row,6,new QTableWidgetItem(strlist.at(6)));
ui->tableHQ_2->setItem(row,7,new QTableWidgetItem(strlist.at(7)));
ui->tableHQ_2->setItem(row,8,new QTableWidgetItem(strlist.at(8)));
ui->tableHQ_2->setItem(row,9,new QTableWidgetItem(strlist.at(9)));
ui->tableHQ_2->setItem(row,10,new QTableWidgetItem(strlist.at(10)));
}
void MainWindow::ReceiveCJ(QString Tick)
{
QStringList strlist = Tick.split(",");
QString buysell = "";
QString openclose = "";
if(strlist.at(2)=="0"){
buysell =QString::fromLocal8Bit("买入");
}
else {
buysell =QString::fromLocal8Bit("卖出");
}
if(strlist.at(3)=="0"){
openclose =QString::fromLocal8Bit("开仓");
}
else if(strlist.at(3)=="4"){
openclose =QString::fromLocal8Bit("平昨");
}
else {
openclose =QString::fromLocal8Bit("平今");
}
int row=ui->tableCJ_2->rowCount();
ui->tableCJ_2->insertRow(row);
ui->tableCJ_2->setItem(row,0,new QTableWidgetItem(strlist.at(0)));
ui->tableCJ_2->setItem(row,1,new QTableWidgetItem(strlist.at(1)));
ui->tableCJ_2->setItem(row,2,new QTableWidgetItem(buysell));
ui->tableCJ_2->setItem(row,3,new QTableWidgetItem(openclose));
ui->tableCJ_2->setItem(row,4,new QTableWidgetItem(strlist.at(4)));
ui->tableCJ_2->setItem(row,5,new QTableWidgetItem(strlist.at(5)));
ui->tableCJ_2->setItem(row,6,new QTableWidgetItem(strlist.at(6)));
ui->tableCJ_2->setItem(row,7,new QTableWidgetItem(strlist.at(7)));
}
void MainWindow::ReceiveWT(QString Tick )
{
QStringList strlist = Tick.split(",");
//if(strlist.at(7)=="")return;
QString buysell = "";
QString openclose = "";
if(strlist.at(2)=="0"){
buysell =QString::fromLocal8Bit("买入");
}
else {
buysell =QString::fromLocal8Bit("卖出");
}
if(strlist.at(3)=="0"){
openclose =QString::fromLocal8Bit("开仓");
}
else if(strlist.at(3)=="4"){
openclose =QString::fromLocal8Bit("平昨");
}
else {
openclose =QString::fromLocal8Bit("平今");
}
for(int i =0;i<ui->tableWT_2->rowCount();i++)
{
if(ui->tableWT_2->item(i,0)->text()==strlist.at(0)){
ui->tableWT_2->setItem(i,0,new QTableWidgetItem(strlist.at(0)));
ui->tableWT_2->setItem(i,1,new QTableWidgetItem(strlist.at(1)));
ui->tableWT_2->setItem(i,2,new QTableWidgetItem(buysell));
ui->tableWT_2->setItem(i,3,new QTableWidgetItem(openclose));
ui->tableWT_2->setItem(i,4,new QTableWidgetItem(strlist.at(4)));
ui->tableWT_2->setItem(i,5,new QTableWidgetItem(strlist.at(5)));
ui->tableWT_2->setItem(i,6,new QTableWidgetItem(strlist.at(6)));
ui->tableWT_2->setItem(i,7,new QTableWidgetItem(strlist.at(7)));
ui->tableWT_2->setItem(i,8,new QTableWidgetItem(strlist.at(8)));
return;
}
}
int row=ui->tableWT_2->rowCount();
ui->tableWT_2->insertRow(row);
ui->tableWT_2->setItem(row,0,new QTableWidgetItem(strlist.at(0)));
ui->tableWT_2->setItem(row,1,new QTableWidgetItem(strlist.at(1)));
ui->tableWT_2->setItem(row,2,new QTableWidgetItem(buysell));
ui->tableWT_2->setItem(row,3,new QTableWidgetItem(openclose));
ui->tableWT_2->setItem(row,4,new QTableWidgetItem(strlist.at(4)));
ui->tableWT_2->setItem(row,5,new QTableWidgetItem(strlist.at(5)));
ui->tableWT_2->setItem(row,6,new QTableWidgetItem(strlist.at(6)));
ui->tableWT_2->setItem(row,7,new QTableWidgetItem(strlist.at(7)));
ui->tableWT_2->setItem(row,8,new QTableWidgetItem(strlist.at(8)));
}
void MainWindow::ReceiveCC(QString Tick)
{
QStringList strlist = Tick.split(",");
QString lx;
if(strlist.at(1)=="2"){
lx = QString::fromLocal8Bit("买");
}
else if(strlist.at(1)=="3"){
lx = QString::fromLocal8Bit("卖");
}
int row=ui->tableCC_2->rowCount();
ui->tableCC_2->insertRow(row);
ui->tableCC_2->setItem(row,0,new QTableWidgetItem(strlist.at(0)));
ui->tableCC_2->setItem(row,1,new QTableWidgetItem(lx));
ui->tableCC_2->setItem(row,2,new QTableWidgetItem(strlist.at(2)));
ui->tableCC_2->setItem(row,3,new QTableWidgetItem(strlist.at(3)));
}
void MainWindow::ReceiveZJ(QString Tick)
{
QStringList strlist = Tick.split(",");
int row=ui->tableZJ_2->rowCount();
ui->tableZJ_2->insertRow(row);
ui->tableZJ_2->setItem(row,0,new QTableWidgetItem(strlist.at(0)));
ui->tableZJ_2->setItem(row,1,new QTableWidgetItem(strlist.at(1)));
ui->tableZJ_2->setItem(row,2,new QTableWidgetItem(strlist.at(2)));
ui->tableZJ_2->setItem(row,3,new QTableWidgetItem(strlist.at(3)));
ui->tableZJ_2->setItem(row,4,new QTableWidgetItem(strlist.at(4)));
}
void MainWindow::ReceiveHY(QString Tick)
{
QStringList strlist = Tick.split(",");
int row=ui->tableHY->rowCount();
ui->tableHY->insertRow(row);
ui->tableHY->setItem(row,0,new QTableWidgetItem(strlist.at(0)));
ui->tableHY->setItem(row,1,new QTableWidgetItem(strlist.at(1)));
ui->tableHY->setItem(row,2,new QTableWidgetItem(strlist.at(2)));
ui->tableHY->setItem(row,3,new QTableWidgetItem(strlist.at(3)));
}
void MainWindow::OnWTmenu(const QPoint &pt)
{
qDebug()<<"onwtmenu";
QMenu menu;
menu.addAction(ui->actioncd);
menu.exec(ui->tableWT_2->mapToGlobal(pt));
}
void MainWindow::ct()
{
if(ui->tableWT_2->rowCount()==0)return;
int i = ui->tableWT_2->currentIndex().row();
QString wth = ui->tableWT_2->item(i,7)->text();
QString jys = ui->tableWT_2->item(i,8)->text();
QString brokerid = "9999";
qDebug()<<wth;
qDebug()<<jys;
if(wth == "")return;
ptdUserSpi->ReqOrderAction(brokerid,wth,jys);
}
void MainWindow::on_pushButton_4_clicked()
{
CThostFtdcReqUserLoginField req ;
memset(&req, 0, sizeof(req));
strcpy(req.BrokerID,"9999");
strcpy(req.UserID,"204925");
strcpy(req.Password,"ThePassword1!");
pUserApi->ReqUserLogin(&req,++iRequestID);
}
void MainWindow::on_pushButton_3_clicked()
{
QString dm = ui->lineEditDm->text();
int lots = ui->lineEditSl->text().toInt();
QString lx;
double Wtprice;
double Sjprice;
double Xjprice;
int index = ui->comboBoxxd->currentIndex();
if(ui->radioButtonsj->isChecked()){
if(index ==0){
lx ="kd";
Sjprice = ui->labelask->text().toDouble();
Wtprice = Sjprice;
}
else if(index ==1){
lx ="pd";
Sjprice = ui->labelbid->text().toDouble();
Wtprice = Sjprice;
}
else if(index ==2){
lx ="kk";
Sjprice = ui->labelbid->text().toDouble();
Wtprice = Sjprice;
}
else if(index ==3){
lx ="pk";
Sjprice = ui->labelask->text().toDouble();
Wtprice = Sjprice;
}
}
else if(ui->radioButtonxj->isChecked()){
if(index ==0){
lx ="kd";
Xjprice = ui->lineEditXj->text().toDouble();
Wtprice = Xjprice;
}
else if(index ==1){
lx ="pd";
Xjprice = ui->lineEditXj->text().toDouble();
Wtprice = Xjprice;
}
else if(index ==2){
lx ="kk";
Xjprice = ui->lineEditXj->text().toDouble();
Wtprice = Xjprice;
}
else if(index ==3){
lx ="pk";
Xjprice = ui->lineEditXj->text().toDouble();
Wtprice = Xjprice;
}
}
ptdUserSpi->ReqOrderInsert(dm,lx,lots,Wtprice);
}
void MainWindow::getSinaData()
{
QNetworkRequest *req = new QNetworkRequest();
QString bumStr = "http://stock2.finance.sina.com.cn/futures/api/json.php/CffexFuturesService.getCffexFuturesMiniKLine15m?symbol=IF1306";
req->setUrl(QUrl(bumStr));
req->setRawHeader("Referer","https://finance.sina.com.cn");
manager->get(*req);
}
void MainWindow::initPlot()
{
QCPFinancial *financial = new QCPFinancial(ui->widget_4->xAxis, ui->widget_4->yAxis);
financial->setName("日K");
financial->setBrushPositive(QColor(255, 43, 82));
financial->setPenPositive(QColor(255, 43, 82));
financial->setBrushNegative(QColor(1, 200, 95));
financial->setPenNegative(QColor(1, 200, 95));
financial->data()->set(datas);
//QCPGraph *graph = ui->widget_4->addGraph(ui->widget_4->xAxis, ui->widget_4->yAxis);
ui->widget_4->setInteraction( QCP::iRangeDrag , true);
ui->widget_4->setInteraction(QCP::iRangeZoom, true);
ui->widget_4->axisRect()->setRangeDrag(Qt::Horizontal);
ui->widget_4->rescaleAxes();
//ui->widget_4->yAxis->scaleRange(0.5, ui->widget_4->yAxis->range().center());
ui->widget_4->xAxis->scaleRange(0.3, ui->widget_4->xAxis->range().center());
ui->widget_4->replot();
}
void MainWindow::finishedSlot(QNetworkReply *rep)
{
//ui->setupUi(this);
if(rep->error() == QNetworkReply::NoError){
QByteArray byte = rep->readAll();
QString str(byte);
qDebug()<<str;
double KeyTime;
double Open,High,Low,Close;
int Vol;
QJsonParseError *error = new QJsonParseError();
QJsonDocument doc= QJsonDocument::fromJson(byte,error);
if(error->error ==QJsonParseError::NoError){
if(doc.isArray()){
QJsonArray array = doc.array();
int size = array.size();
for(int i =0;i<size;i++){
QJsonValue va = array.at(i);
if(va.isArray()){
QJsonArray array1 = va.toArray();
KeyTime = array1.at(0).toDouble();
Open = array1.at(1).toDouble();
High =array1.at(2).toDouble();
Low = array1.at(3).toDouble();
Close =array1.at(4).toDouble();
Vol = array1.at(5).toInt();
QCPFinancialData data;
data.key = i;
data.open = array1.at(1).toString().toDouble();
data.close = array1.at(4).toString().toDouble();
data.low = array1.at(3).toString().toDouble();
data.high = array1.at(2).toString().toDouble();
datas.add(data);
}
}
}
}
}
else
qDebug()<<"error"<<rep->error();
initPlot();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化