mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
update vegetables price
This commit is contained in:
parent
16d0f82c4c
commit
afe8df7ab9
4
QQt.pro
4
QQt.pro
@ -22,9 +22,9 @@ SUBDIRS = src/qqt.pro
|
||||
#SUBDIRS += examples/tabwidgetexamples
|
||||
#SUBDIRS += examples/svgtest
|
||||
#SUBDIRS += examples/treeviewexample
|
||||
#SUBDIRS += examples/qrcodeexample
|
||||
#
|
||||
SUBDIRS += examples/qrcodeexample
|
||||
#SUBDIRS += examples/gumbo_query_test
|
||||
SUBDIRS += examples/gumbo_query_test
|
||||
|
||||
#can't support ios
|
||||
#SUBDIRS += examples/qqtprintsupportexample
|
||||
|
@ -1,7 +1,11 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include "QDebug"
|
||||
#include <GumboQueryDocument.h>
|
||||
#include <GumboQuerySelection.h>
|
||||
#include <GumboQueryNode.h>
|
||||
#include <QStringList>
|
||||
#include <QStringListIterator>
|
||||
|
||||
MainWindow::MainWindow ( QWidget* parent ) :
|
||||
QMainWindow ( parent ),
|
||||
@ -9,6 +13,10 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
|
||||
m_client = new QQtWebWorkClient ( this );
|
||||
connect ( m_client, SIGNAL ( replyFinished ( QNetworkReply* ) ),
|
||||
this, SLOT ( replyFinished ( QNetworkReply* ) ) );
|
||||
|
||||
QStringList vl;
|
||||
vl << "西葫芦";
|
||||
vl << "土豆";
|
||||
@ -35,7 +43,9 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||
vl << "蒜薹";
|
||||
vl << "豆角";
|
||||
vl << "茴香";
|
||||
ui->lw->addItems(vl);
|
||||
m_mapVege["西葫芦"] = "xihulu" ;
|
||||
m_mapVege["土豆"] = "tudou";
|
||||
ui->lw->addItems ( m_mapVege.keys() );
|
||||
|
||||
|
||||
connect ( ui->lw, SIGNAL ( currentItemChanged ( QListWidgetItem*, QListWidgetItem* ) ),
|
||||
@ -52,9 +62,103 @@ MainWindow::~MainWindow()
|
||||
void MainWindow::currentItemChanged ( QListWidgetItem* cur, QListWidgetItem* prev )
|
||||
{
|
||||
qDebug() << cur << prev;
|
||||
|
||||
if ( !cur )
|
||||
return;
|
||||
|
||||
QString url = QString("http://www.baidu.com/s?wd=%1%2").arg(cur->text()).arg("价格");
|
||||
|
||||
//QString url = QString ( "http://www.baidu.com/s?wd=%1%2" ).arg ( cur->text() ).arg ( "价格" );
|
||||
QString url = QString ( "http://nong.gold600.com/cx?pz=%1&c=shandong" ).arg ( m_mapVege[cur->text()] );
|
||||
m_client->sendGetRequest ( url );
|
||||
}
|
||||
|
||||
void MainWindow::replyFinished ( QNetworkReply* reply )
|
||||
{
|
||||
//pline() << reply->readAll();
|
||||
int nHttpCode = reply->attribute ( QNetworkRequest::HttpStatusCodeAttribute ).toInt(); //http返回码
|
||||
|
||||
if ( nHttpCode == 200 ) //成功
|
||||
{
|
||||
pline() << "success";
|
||||
}
|
||||
else
|
||||
{
|
||||
pline() << "fail";
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray resultContent = reply->readAll();
|
||||
//pline() << QString ( resultContent );
|
||||
/*用页面源文件的编码来进行解码 GB2312 or UTF-8*/
|
||||
QTextCodec* pCodec = QTextCodec::codecForName ( "GB2312" );
|
||||
QString strResult = pCodec->toUnicode ( resultContent );
|
||||
//pline() << strResult;
|
||||
QTextCodec* pCodec2 = QTextCodec::codecForName ( "GB2312" );
|
||||
QByteArray strResult2 = pCodec2->fromUnicode ( strResult );
|
||||
QString txt0 = strResult2;
|
||||
//pline() << txt0;
|
||||
QString cc = resultContent;
|
||||
//pline() << cc.toLatin1().constData();
|
||||
|
||||
GumboQueryDocument doc;
|
||||
doc.parse ( strResult.toLocal8Bit().constData() );
|
||||
GumboQuerySelection s = doc.find ( "table" );
|
||||
|
||||
GumboQueryNode pNode = s.nodeAt ( 0 );
|
||||
QString txt = QString::fromStdString ( pNode.text() );
|
||||
|
||||
//pline() << txt;
|
||||
QStringList tList = txt.split ( "\n", QString::SkipEmptyParts );
|
||||
|
||||
|
||||
for ( int i = 0; i < tList.count(); i++ )
|
||||
{
|
||||
QString txt = tList.at ( i );
|
||||
txt = txt.trimmed();
|
||||
|
||||
if ( txt.isEmpty() )
|
||||
{
|
||||
tList.removeAt ( i );
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
tList[i] = txt;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
for ( QStringList::Iterator itor = tList.begin();
|
||||
itor != tList.end(); itor++ )
|
||||
{
|
||||
QString txt = ( QString ) * itor;
|
||||
|
||||
if ( "" == txt.trimmed() )
|
||||
{
|
||||
tList.erase ( itor );
|
||||
itor--;
|
||||
continue;
|
||||
}
|
||||
|
||||
*itor = txt.trimmed();
|
||||
}
|
||||
*/
|
||||
|
||||
ui->tb->clear();
|
||||
ui->tb->setColumnCount ( 5 );
|
||||
ui->tb->horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeToContents );
|
||||
|
||||
|
||||
for ( int i = 0; i < tList.count(); )
|
||||
{
|
||||
ui->tb->setRowCount ( i / 5 + 1 );
|
||||
|
||||
for ( int j = 0; j < 5; j++ )
|
||||
{
|
||||
QString cc = tList.value ( i );
|
||||
qDebug() << i / 5 << j << cc;
|
||||
QTableWidgetItem* item = new QTableWidgetItem ( cc );
|
||||
ui->tb->setItem ( i / 5, j, item );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,10 @@
|
||||
#include <QMainWindow>
|
||||
#include <QListWidget>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
#include "qqtcore.h"
|
||||
#include "qqtwebworkclient.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
@ -18,9 +20,11 @@ public:
|
||||
~MainWindow();
|
||||
private slots:
|
||||
void currentItemChanged ( QListWidgetItem*, QListWidgetItem* );
|
||||
|
||||
void replyFinished ( QNetworkReply* reply );
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
QQtWebWorkClient* m_client;
|
||||
QMap<QString, QString> m_mapVege;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>889</width>
|
||||
<height>444</height>
|
||||
<width>647</width>
|
||||
<height>330</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -32,7 +32,13 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tb"/>
|
||||
<widget class="QTableWidget" name="tb">
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>fff</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -41,7 +47,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>889</width>
|
||||
<width>647</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -28,7 +28,7 @@ QQtWebWorkClient::QQtWebWorkClient ( QObject* parent ) : QNetworkAccessManager (
|
||||
this, SLOT ( networkSessionConnected() ) );
|
||||
}
|
||||
|
||||
void QQtWebWorkClient::getRequest ( QString& strUrl )
|
||||
void QQtWebWorkClient::sendGetRequest ( QString& strUrl )
|
||||
{
|
||||
QQtWebWorkSession* s0 = new QQtWebWorkSession ( this );
|
||||
|
||||
@ -52,6 +52,7 @@ void QQtWebWorkClient::getRequest ( QString& strUrl )
|
||||
}
|
||||
|
||||
s0->m_pNetworkReply = get ( netRequest ); //发起get请求
|
||||
m_listWebWorkSession.push_back ( s0 );
|
||||
/*下面关联信号和槽*/
|
||||
|
||||
/*下载完成后开始一阵一阵堆取数据*/
|
||||
@ -71,7 +72,7 @@ void QQtWebWorkClient::getRequest ( QString& strUrl )
|
||||
s0->m_pTimer->start ( );
|
||||
}
|
||||
|
||||
void QQtWebWorkClient::postRequest ( QString& strUrl )
|
||||
void QQtWebWorkClient::sendPostRequest ( QString& strUrl )
|
||||
{
|
||||
//post
|
||||
// QString strBody; //http body部分,可封装参数信息
|
||||
@ -101,9 +102,11 @@ void QQtWebWorkClient::finished ( QNetworkReply* reply )
|
||||
if ( !s0 )
|
||||
return;
|
||||
|
||||
pline() << s0->m_pNetworkReply << s0->m_pTimer;
|
||||
|
||||
s0->m_pTimer->stop();
|
||||
s0->m_pNetworkReply->deleteLater();
|
||||
m_listWebWorkSession.removeOne ( s0 );
|
||||
|
||||
}
|
||||
|
||||
void QQtWebWorkClient::authenticationRequired ( QNetworkReply* r, QAuthenticator* a )
|
||||
|
@ -17,27 +17,15 @@
|
||||
* Multi New Protocol 全双工 QWebSocket
|
||||
* need ssl
|
||||
*/
|
||||
class QQtWebWorkSession : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtWebWorkSession ( QObject* parent ) :
|
||||
QObject ( parent ) {}
|
||||
virtual ~QQtWebWorkSession() {}
|
||||
|
||||
QNetworkReply* m_pNetworkReply; //封装请求返回信息
|
||||
QTimer* m_pTimer; //请求超时计时器
|
||||
QString m_strUrl; //记录当前请求的url
|
||||
} ;
|
||||
|
||||
class QQtWebWorkSession;
|
||||
class QQTSHARED_EXPORT QQtWebWorkClient : public QNetworkAccessManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtWebWorkClient ( QObject* parent = 0 );
|
||||
|
||||
void getRequest ( QString& strUrl );
|
||||
void postRequest ( QString& strUrl );
|
||||
void sendGetRequest ( QString& strUrl );
|
||||
void sendPostRequest ( QString& strUrl );
|
||||
//void installProtocol();
|
||||
//void uninstallProtocol();
|
||||
|
||||
@ -70,4 +58,17 @@ private:
|
||||
QList<QQtWebWorkSession*> m_listWebWorkSession;
|
||||
};
|
||||
|
||||
class QQtWebWorkSession : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtWebWorkSession ( QObject* parent ) :
|
||||
QObject ( parent ) {}
|
||||
virtual ~QQtWebWorkSession() {}
|
||||
|
||||
QNetworkReply* m_pNetworkReply; //封装请求返回信息
|
||||
QTimer* m_pTimer; //请求超时计时器
|
||||
QString m_strUrl; //记录当前请求的url
|
||||
} ;
|
||||
|
||||
#endif // QQTWEBWORKCLIENT_H
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include "qqtsql.h"
|
||||
#include "qqt-qt.h"
|
||||
|
||||
QQTMPTableWidget::QQTMPTableWidget(QWidget* parent) :
|
||||
QQtMPTableWidget::QQtMPTableWidget ( QWidget* parent ) :
|
||||
QWidget ( parent ),
|
||||
ui(new Ui::QQTMPTableWidget)
|
||||
ui ( new Ui::QQtMPTableWidget )
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
|
||||
@ -33,28 +33,28 @@ QQTMPTableWidget::QQTMPTableWidget(QWidget* parent) :
|
||||
|
||||
}
|
||||
|
||||
QQTMPTableWidget::~QQTMPTableWidget()
|
||||
QQtMPTableWidget::~QQtMPTableWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setDB(QString db)
|
||||
void QQtMPTableWidget::setDB ( QString db )
|
||||
{
|
||||
m_name = db;
|
||||
setDatabaseName ( m_db, m_name );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setTable(QString table)
|
||||
void QQtMPTableWidget::setTable ( QString table )
|
||||
{
|
||||
m_table = table;
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setRelation(int column, const QSqlRelation& relation)
|
||||
void QQtMPTableWidget::setRelation ( int column, const QSqlRelation& relation )
|
||||
{
|
||||
m_columnRelation.insert ( column, relation );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::query(QString filter)
|
||||
void QQtMPTableWidget::query ( QString filter )
|
||||
{
|
||||
ptime(); //3ms
|
||||
|
||||
@ -160,17 +160,17 @@ void QQTMPTableWidget::query(QString filter)
|
||||
}
|
||||
}
|
||||
|
||||
int QQTMPTableWidget::pageNum()
|
||||
int QQtMPTableWidget::pageNum()
|
||||
{
|
||||
return m_pageNum;
|
||||
}
|
||||
|
||||
int QQTMPTableWidget::currentPage()
|
||||
int QQtMPTableWidget::currentPage()
|
||||
{
|
||||
return ui->stWidgetPage->currentIndex() + 1;
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setCurrentPage(int index)
|
||||
void QQtMPTableWidget::setCurrentPage ( int index )
|
||||
{
|
||||
if ( index < 1 || index > m_pageNum )
|
||||
return;
|
||||
@ -179,47 +179,47 @@ void QQTMPTableWidget::setCurrentPage(int index)
|
||||
ui->lbPos->setText ( QString ( "%1/%2" ).arg ( index ).arg ( m_pageNum ) );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setRecordNumPerPage(int num)
|
||||
void QQtMPTableWidget::setRecordNumPerPage ( int num )
|
||||
{
|
||||
m_numPerPage = num;
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setColumnHidden(int key, bool value)
|
||||
void QQtMPTableWidget::setColumnHidden ( int key, bool value )
|
||||
{
|
||||
m_columnHidden.insert ( key, value );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setSelectionMode(QAbstractItemView::SelectionMode mode)
|
||||
void QQtMPTableWidget::setSelectionMode ( QAbstractItemView::SelectionMode mode )
|
||||
{
|
||||
selectionMode = mode;
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setResizeMode(QHeaderView::ResizeMode mode)
|
||||
void QQtMPTableWidget::setResizeMode ( QHeaderView::ResizeMode mode )
|
||||
{
|
||||
resizeMode = mode;
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setResizeMode(int column, QHeaderView::ResizeMode mode)
|
||||
void QQtMPTableWidget::setResizeMode ( int column, QHeaderView::ResizeMode mode )
|
||||
{
|
||||
m_resizeMode.insert ( column, mode );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setAlternatingRowColors(bool alt)
|
||||
void QQtMPTableWidget::setAlternatingRowColors ( bool alt )
|
||||
{
|
||||
altColor = alt;
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setHeaderData(int i, Qt::Orientation, QString data)
|
||||
void QQtMPTableWidget::setHeaderData ( int i, Qt::Orientation, QString data )
|
||||
{
|
||||
m_headerData.insert ( i, data );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::setColumnWidth(int column, int width)
|
||||
void QQtMPTableWidget::setColumnWidth ( int column, int width )
|
||||
{
|
||||
m_columnWidth.insert ( column, width );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::on_btnLeft_clicked()
|
||||
void QQtMPTableWidget::on_btnLeft_clicked()
|
||||
{
|
||||
int index = ui->stWidgetPage->currentIndex();
|
||||
|
||||
@ -230,7 +230,7 @@ void QQTMPTableWidget::on_btnLeft_clicked()
|
||||
ui->lbPos->setText ( QString ( "%1/%2" ).arg ( index + 1 ).arg ( m_pageNum ) );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::on_btnRight_clicked()
|
||||
void QQtMPTableWidget::on_btnRight_clicked()
|
||||
{
|
||||
int index = ui->stWidgetPage->currentIndex();
|
||||
|
||||
@ -241,7 +241,7 @@ void QQTMPTableWidget::on_btnRight_clicked()
|
||||
ui->lbPos->setText ( QString ( "%1/%2" ).arg ( index + 1 ).arg ( m_pageNum ) );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::on_btnJump_clicked()
|
||||
void QQtMPTableWidget::on_btnJump_clicked()
|
||||
{
|
||||
int num = ui->leNum->text().toInt();
|
||||
|
||||
@ -252,20 +252,20 @@ void QQTMPTableWidget::on_btnJump_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::on_btnLeftHead_clicked()
|
||||
void QQtMPTableWidget::on_btnLeftHead_clicked()
|
||||
{
|
||||
ui->stWidgetPage->setCurrentIndex ( 0 );
|
||||
ui->lbPos->setText ( QString ( "%1/%2" ).arg ( 1 ).arg ( m_pageNum ) );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::on_btnRightHead_clicked()
|
||||
void QQtMPTableWidget::on_btnRightHead_clicked()
|
||||
{
|
||||
int index = m_pageNum - 1;
|
||||
ui->stWidgetPage->setCurrentIndex ( index );
|
||||
ui->lbPos->setText ( QString ( "%1/%2" ).arg ( index + 1 ).arg ( m_pageNum ) );
|
||||
}
|
||||
|
||||
void QQTMPTableWidget::selectedRows(int column, QVector<QStringList>& strl)
|
||||
void QQtMPTableWidget::selectedRows ( int column, QVector<QStringList>& strl )
|
||||
{
|
||||
for ( int i = 0; i < m_pageNum; i++ )
|
||||
{
|
||||
@ -284,7 +284,7 @@ void QQTMPTableWidget::selectedRows(int column, QVector<QStringList>& strl)
|
||||
return;
|
||||
}
|
||||
|
||||
QQtTableWidget* QQTMPTableWidget::selectedRows(int column)
|
||||
QQtTableWidget* QQtMPTableWidget::selectedRows ( int column )
|
||||
{
|
||||
QString sectionName;
|
||||
QSqlQuery query ( m_db );
|
||||
@ -338,7 +338,7 @@ QQtTableWidget* QQTMPTableWidget::selectedRows(int column)
|
||||
}
|
||||
|
||||
|
||||
void QQTMPTableWidget::removeSelectedRows(int column)
|
||||
void QQtMPTableWidget::removeSelectedRows ( int column )
|
||||
{
|
||||
for ( int i = 0; i < m_pageNum; i++ )
|
||||
{
|
||||
|
@ -9,22 +9,22 @@
|
||||
#include "qqt-local.h"
|
||||
|
||||
namespace Ui {
|
||||
class QQTMPTableWidget;
|
||||
class QQtMPTableWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The QQTMPTableWidget class
|
||||
* @brief The QQtMPTableWidget class
|
||||
* 关于视图规格的改变改变到上层
|
||||
* 这里的控件使用默认视图
|
||||
* 这里的控件只是Table-DB关系,没有Tree/List模型
|
||||
*/
|
||||
class QQTSHARED_EXPORT QQTMPTableWidget : public QWidget
|
||||
class QQTSHARED_EXPORT QQtMPTableWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QQTMPTableWidget(QWidget* parent = 0);
|
||||
~QQTMPTableWidget();
|
||||
explicit QQtMPTableWidget ( QWidget* parent = 0 );
|
||||
~QQtMPTableWidget();
|
||||
|
||||
void setDB ( QString db );
|
||||
void setTable ( QString table );
|
||||
@ -59,7 +59,7 @@ private slots:
|
||||
void on_btnRightHead_clicked();
|
||||
|
||||
private:
|
||||
Ui::QQTMPTableWidget* ui;
|
||||
Ui::QQtMPTableWidget* ui;
|
||||
QSqlDatabase m_db;
|
||||
QString m_name;
|
||||
QString m_table;
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QQTMPTableWidget</class>
|
||||
<widget class="QWidget" name="QQTMPTableWidget">
|
||||
<class>QQtMPTableWidget</class>
|
||||
<widget class="QWidget" name="QQtMPTableWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
|
Loading…
x
Reference in New Issue
Block a user