| | |
| | | #include <QJsonObject> |
| | | #include <QJsonArray> |
| | | #include <QLibrary> // 用于加载dll动态库的类 |
| | | #include <QDateTime> |
| | | |
| | | |
| | | #pragma execution_character_set("utf-8") |
| | | |
| | | GetStockList::GetStockList(QWidget *parent) : |
| | | QMainWindow(parent), |
| | |
| | | ui->pushButton_get->hide(); |
| | | ui->statusbar->hide(); |
| | | |
| | | // 注册元类型 |
| | | qRegisterMetaType<QVector<QVector<QString>>>("QVector<QVector<QString>> &"); |
| | | // 方案2: |
| | | // 如果https 访问的时候,还是爬取失败,可以代码加载动态库来支持 |
| | | // 前提条件是把2个dll动态库拷贝的生成目录中:libeay32.dll 和 ssleay32.dll |
| | | // 拷贝到生成目录,就可以直接加载 |
| | | // 若是msvc 64bit的编译器,需要下载对应位数的dll库来拷贝即可 -- openssl-1.0.2q-x64_86-win64.zip |
| | | |
| | | QLibrary lb("libeay32.dll"); |
| | | if(lb.load()){ |
| | | qDebug()<<"load libeay32.dll 成功"; |
| | |
| | | |
| | | // 支持编辑框的模糊匹配 |
| | | m_completer = new QCompleter(this); |
| | | m_completer->setModel(m_customModel); |
| | | m_completer->setModel(m_customModel); // 关联包含所有匹配内容的模型或者字符串链表 |
| | | m_completer->setCaseSensitivity(Qt::CaseInsensitive); // 不区分大小写 |
| | | m_completer->setCompletionMode(QCompleter::PopupCompletion); // 自动显示下拉框 |
| | | m_completer->setFilterMode(Qt::MatchStartsWith); // 前缀匹配 |
| | | m_completer->setFilterMode(Qt::MatchContains); // 前缀匹配、包含、后缀 |
| | | ui->lineEdit_search->setCompleter(m_completer); // 关联匹配的控件 |
| | | |
| | | } |
| | |
| | | m_model->appendRow(rowItems); |
| | | } |
| | | } |
| | | |
| | | // 发射信号 |
| | | emit sendCodeNames(m_codeNames); |
| | | } |
| | | |
| | | |
| | |
| | | if(ma5 >= open && ma10 >= open && ma20 >= open && ma30 >= open |
| | | && ma5 <= close && ma10 <= close && ma20 <= close && ma30 <= close){ |
| | | qDebug()<<"一阳穿四线:"<< code <<curDateTime<<" 价格:"<<close << "量能比:"<<volume_rate; |
| | | QString info = QString("<font size=8 color=red> %3 %4 一阳穿四线:%1 价格:%2 量能比:%5 周期:%6 市值:%7亿</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) |
| | | .arg(m_dateType).arg(market_cap/100000000.0); |
| | | emit sendInfoMess(info); |
| | | if(volume_rate > 4){ |
| | | QString info = QString("<font size=8 color=blue> %3 %4 一阳穿四线:%1 价格:%2 量能比:%5 周期:%6 市值:%7亿</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) |
| | | .arg(m_dateType).arg(market_cap/100000000.0); |
| | | emit sendInfoMess(info); |
| | | }else{ |
| | | QString info = QString("<font size=8 color=red> %3 %4 一阳穿四线:%1 价格:%2 量能比:%5 周期:%6 市值:%7亿</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) |
| | | .arg(m_dateType).arg(market_cap/100000000.0); |
| | | emit sendInfoMess(info); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | void GetStockList::on_pushButton_search_clicked() |
| | | { |
| | | ui->tableView->clearSelection(); |
| | | QString condition = ui->lineEdit_search->text(); |
| | | for(int i =0;i<m_customModel->rowCount();++i){ |
| | | if(m_customModel->data(m_customModel->index(i,0)).toString() == condition |
| | | || m_customModel->data(m_customModel->index(i,1)).toString() == condition) |
| | | { |
| | | ui->tableView->setCurrentIndex(m_customModel->index(i,0)); |
| | | //ui->tableView->setCurrentIndex(m_customModel->index(i,0)); |
| | | ui->tableView->selectRow(i); |
| | | break; |
| | | } |
| | | } |
| | |
| | | { |
| | | on_pushButton_search_clicked(); |
| | | } |
| | | |
| | | void GetStockList::showHistoryModelData(QVector<QVector<QString>> &model) // 从历史那边将数据发过来 |
| | | { |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | m_model->setRowCount(0); |
| | | for(int i=0;i<model.size();++i){ |
| | | //qDebug()<<"i="<<i; |
| | | QList<QStandardItem*> items; |
| | | m_codeNames[model[i][1]] = model[i][0]; |
| | | for(int j=0;j<model.at(0).size();++j){ |
| | | items.append(new QStandardItem(model[i][j])); |
| | | |
| | | if(j==2){ |
| | | items.append(new QStandardItem(model[i][j])); |
| | | } |
| | | if(j==3){ |
| | | QStandardItem *percentItem = items.back(); |
| | | if(percentItem->text().toDouble() > 0){ |
| | | percentItem->setData(QColor("red"),Qt::DecorationRole); // 添加一个装饰的颜色为红色 |
| | | percentItem->setData(QColor("red"),Qt::TextColorRole); // 将字体颜色设置为红色 |
| | | items.at(0)->setData(QColor("red"),Qt::TextColorRole); // 将股票名字设置为红色 |
| | | } |
| | | else if(percentItem->text().toDouble() < 0){ |
| | | percentItem->setData(QColor("green"),Qt::BackgroundColorRole); |
| | | items.at(0)->setData(QColor("green"),Qt::TextColorRole); |
| | | } |
| | | } |
| | | |
| | | } |
| | | m_model->appendRow(items); |
| | | } |
| | | qDebug()<<"历史到信息赋值完成 行数:"<<m_model->rowCount(); |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | } |
| | | |
| | | void GetStockList::showHistoryModelData(QStandardItemModel *model) |
| | | { |
| | | |
| | | // qDebug()<<QDateTime::currentDateTime(); |
| | | // //ui->tableView->setModel(model); |
| | | // QVector<QVector<QString>> vec; |
| | | // for(int i=0;i<model->rowCount();++i){ |
| | | // //QString row; |
| | | // QVector<QString> tmp; |
| | | |
| | | // m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text(); |
| | | |
| | | // for(int j=0;j<model->columnCount();++j){ |
| | | // //row+=model->item(i,j)->text()+" "; |
| | | // tmp.append(model->item(i,j)->text()); |
| | | // } |
| | | // //qDebug()<<i<<row; |
| | | // vec.append(tmp); |
| | | // } |
| | | // qDebug()<<"vec size:"<<vec.size(); |
| | | |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | m_model->setRowCount(0); |
| | | for(int i=0;i<model->rowCount();++i){ |
| | | QList<QStandardItem*> items; |
| | | m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text(); |
| | | for(int j=0;j<model->columnCount();++j){ |
| | | items.append(new QStandardItem(model->item(i,j)->text())); |
| | | if(j==2){ |
| | | items.append(new QStandardItem(model->item(i,j)->text())); |
| | | } |
| | | if(j==3){ |
| | | QStandardItem *percentItem = items.back(); |
| | | if(percentItem->text().toDouble() > 0){ |
| | | percentItem->setData(QColor("red"),Qt::DecorationRole); // 添加一个装饰的颜色为红色 |
| | | percentItem->setData(QColor("red"),Qt::TextColorRole); // 将字体颜色设置为红色 |
| | | items.at(0)->setData(QColor("red"),Qt::TextColorRole); // 将股票名字设置为红色 |
| | | } |
| | | else if(percentItem->text().toDouble() < 0){ |
| | | percentItem->setData(QColor("green"),Qt::BackgroundColorRole); |
| | | items.at(0)->setData(QColor("green"),Qt::TextColorRole); |
| | | } |
| | | } |
| | | } |
| | | m_model->appendRow(items); |
| | | } |
| | | qDebug()<<"历史到信息赋值完成 条数:"<<m_model->rowCount(); |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | } |