星小夜的登录器  v1.0
pettip.cpp
浏览该文件的文档.
1 
10 #include "pettip.h"
11 #include "ui_pettip.h"
12 #include <QString>
13 #include "ext.h"
19 Pettip::Pettip(QWidget *parent) :
20  QWidget(parent),
21  ui(new Ui::Pettip)
22 {
23  ui->setupUi(this);
24  setAttribute(Qt::WA_QuitOnClose,false);
25  //ui->axWidget->setControl(QString::fromUtf8("{8856F961-340A-11D0-A96B-00C04FD705A2}"));//注册组件ID
26  //ui->axWidget->setProperty("DisplayAlerts",false);//不显示警告信息
27  //ui->axWidget->setProperty("DisplayScrollBars",true);//不显示滚动条
28  m_manager = new QNetworkAccessManager(this);//新建QNetworkAccessManager对象
29  connect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(slot_replayFinished(QNetworkReply*))); //关联信号和槽
30  connect(ui->pushButton,SIGNAL(clicked(bool)),this,SLOT(slot_buttonget()));
31 
32  QFile file(allpath+"/json/data.json");
33  file.open(QIODevice::ReadOnly | QIODevice::Text);
34  QString value = file.readAll();
35  file.close();
36 
37  QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
38  jsonObject = document.object();
39 
40 
41 
42 
43 }
49  petname=ui->textEdit->toPlainText();
50  qDebug()<<jsonObject[petname];
51  if(jsonObject[petname].isNull())
52  emit sendmes("当前精灵不存在,请输入完整名字");
53  else{
54  if (!(parseJsonErr.error == QJsonParseError::NoError)) {
55  qDebug()<<"配置文件错误!";
56  return;
57  }
58  emit sendmes(petname+"的技能查询中");
59  m_manager->get(QNetworkRequest(QUrl(jsonObject[petname].toString())));//发送请求
60  }
61 }
67 void Pettip::slot_getname(QString name){
68 
69  petname=name;
70  qDebug()<<jsonObject[petname];
71  if(jsonObject[petname].isNull())
72  emit sendmes("当前精灵不存在,请输入完整名字");
73  else{
74  if (!(parseJsonErr.error == QJsonParseError::NoError)) {
75  qDebug()<<"配置文件错误!";
76  return;
77  }
78  m_manager->get(QNetworkRequest(QUrl(jsonObject[petname].toString())));//发送请求
79  }
80 }
86 {
87  delete ui;
88  delete m_manager;
89 }
96  //ui->axWidget->setControl(QString::fromUtf8("{d27cdb6e-ae6d-11cf-96b8-444553540000}"));
97  //ui->axWidget->setControl(QString::fromUtf8("{8856F961-340A-11D0-A96B-00C04FD705A2}"));//注册组件ID
98  //QString str=QString("http://news.4399.com/seer/tujian/64106.htm");//设置要打开的网页
99  //ui->axWidget->dynamicCall("Navigate(QString)",str);//显示网页
100 
101 
102 }
108 void Pettip::slot_replayFinished(QNetworkReply *reply)
109 {
110  QTextCodec *codec = QTextCodec::codecForName("GBK");
111  //使用utf8编码, 这样可以显示中文
112  QString str = codec->toUnicode(reply->readAll());
113  //qDebug()<<str;
114  str.replace(QString("\n"), QString(""));
115  str.replace(QString("\t"), QString(""));
116  str.replace(QString("\r"), QString(""));
117 
118  QString tmp;
119  QStringList li=str.split("<tbody>");
120  QStringList li1;
121  for(int i=0;i<li.length();i++){
122  li1=li[i].split("</tbody>");
123  if(li1.length()!=0)
124  tmp=li1[0];
125  }
126  //tmp.replace("<td>","");
127  //tmp.replace("</td>","");
128  ui->tableWidget->clear();
129  ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//
130  ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
131  li=tmp.split("</tr>");
132  QStringList header;
133  header << QStringLiteral("技能名") << QStringLiteral("攻击类型") << QStringLiteral("威力")<<QStringLiteral("PP")<<QStringLiteral("学习等级")<<"技能效果";
134  ui->tableWidget->setRowCount(li.length());
135  ui->tableWidget->setColumnCount(6);
136  ui->tableWidget->setHorizontalHeaderLabels(header);
137  ui->tableWidget->horizontalHeader()->setSectionResizeMode(0,QHeaderView::ResizeToContents);
138  ui->tableWidget->horizontalHeader()->setSectionResizeMode(1,QHeaderView::ResizeToContents);
139  ui->tableWidget->horizontalHeader()->setSectionResizeMode(2,QHeaderView::ResizeToContents);
140  ui->tableWidget->horizontalHeader()->setSectionResizeMode(3,QHeaderView::ResizeToContents);
141  ui->tableWidget->horizontalHeader()->setSectionResizeMode(4,QHeaderView::ResizeToContents);
142  ui->tableWidget->horizontalHeader()->setSectionResizeMode(5,QHeaderView::ResizeToContents);
143  for(int i=0;i<li.length();i++){
144  li1=li[i].split("</td>");
145  for(int j=0;j<li1.length();j++){
146  li1[j].replace("<td>","");
147  li1[j].replace("<td style=\"text-align:left\">","");
148  li1[j].replace("<tr>","");
149  li1[j].replace("<tr class=\"odd\">","");
150  if(li1[j].indexOf("check")!=-1 || li1[j].indexOf("rel")!=-1)
151  break;
152  ui->tableWidget->setItem(i, j, new QTableWidgetItem(li1[j]));
153  qDebug()<<li1[j];
154  }
155  }
156  //qDebug()<<str.indexOf("<tbody>");
157  //qDebug()<<str.indexOf("</tbody>");
158  //qDebug()<<str.mid(str.indexOf("<tbody>"),str.indexOf("</tbody>"));
159  //qDebug()<<str;
160  //QRegExp rx("<tbody.*?>*</tbody>");
161  //QRegExp rx("[a-zA-z]+://[^\\s]*");
162  //int pos = rx.indexIn(str);
163  //qDebug() << pos;
164  //for(int i=0;i<pos;i++)
165  // qDebug()<<rx.cap(i);
166  reply->deleteLater();//最后要释放replay对象
167 }
pettip.h
精灵技能快查窗口头文件
Pettip::slot_replayFinished
void slot_replayFinished(QNetworkReply *reply)
读取精灵技能
Definition: pettip.cpp:108
Pettip::ui
Ui::Pettip * ui
Definition: pettip.h:56
Pettip::sendmes
void sendmes(QString msg)
Pettip::jsonObject
QJsonObject jsonObject
Definition: pettip.h:44
Pettip::slot_tip
void slot_tip()
展示查询内容(ie控件模式)
Definition: pettip.cpp:95
Pettip::petname
QString petname
Definition: pettip.h:43
Pettip::parseJsonErr
QJsonParseError parseJsonErr
Definition: pettip.h:45
allpath
QString allpath
登录器运行目录
Definition: ext.cpp:45
Ui
Definition: atoken.h:17
Pettip::m_manager
QNetworkAccessManager * m_manager
Definition: pettip.h:47
Pettip
精灵技能快查窗口类 这个类写了整整一天,格式化精灵技能真难
Definition: pettip.h:37
Pettip::slot_getname
void slot_getname(QString name)
读取json中精灵名称对应的图鉴地址
Definition: pettip.cpp:67
Pettip::Pettip
Pettip(QWidget *parent=0)
精灵技能快查窗口构造函数
Definition: pettip.cpp:19
Pettip::~Pettip
~Pettip()
精灵技能快查窗口析构函数
Definition: pettip.cpp:85
ext.h
全局变量声明头文件
Pettip::slot_buttonget
void slot_buttonget()
精灵技能查询
Definition: pettip.cpp:48