| | |
| | | #include <QJsonObject> |
| | | #include <QJsonArray> |
| | | #include <QLibrary> // 用于加载dll动态库的类 |
| | | #include <QDateTime> |
| | | |
| | | |
| | | #pragma execution_character_set("utf-8") |
| | |
| | | ui->pushButton_get->hide(); |
| | | ui->statusbar->hide(); |
| | | |
| | | // 注册元类型 |
| | | qRegisterMetaType<QVector<QVector<QString>>>("QVector<QVector<QString>> &"); |
| | | // 方案2: |
| | | // 如果https 访问的时候,还是爬取失败,可以代码加载动态库来支持 |
| | | // 前提条件是把2个dll动态库拷贝的生成目录中:libeay32.dll 和 ssleay32.dll |
| | |
| | | m_model->appendRow(rowItems); |
| | | } |
| | | } |
| | | |
| | | // 发射信号 |
| | | emit sendCodeNames(m_codeNames); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | 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(); |
| | | } |