mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
fix linux qt4 build
This commit is contained in:
parent
70cd411dc2
commit
858c8c89d5
10
QQt.pro
10
QQt.pro
@ -1,8 +1,7 @@
|
||||
TEMPLATE = subdirs
|
||||
CONFIG += ordered
|
||||
|
||||
SUBDIRS = src/qqt.pro \
|
||||
examples/qqthttpdownload
|
||||
SUBDIRS = src/qqt.pro
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
#basic example
|
||||
@ -20,10 +19,11 @@ SUBDIRS += examples/animationframe
|
||||
SUBDIRS += examples/exquisite
|
||||
SUBDIRS += examples/tabwidgetexamples
|
||||
SUBDIRS += examples/qrcodeexample
|
||||
SUBDIRS += examples/qqtnetworkexample
|
||||
greaterThan(QT_MAJOR_VERSION , 4):SUBDIRS += examples/qqtnetworkexample
|
||||
SUBDIRS += examples/QtBuildTool
|
||||
SUBDIRS += examples/QtSdkManager
|
||||
SUBDIRS += examples/QQtInstaller
|
||||
greaterThan(QT_MAJOR_VERSION, 4):SUBDIRS += examples/qqthttpdownload
|
||||
|
||||
#can't support ios
|
||||
SUBDIRS += examples/qqtprintsupportexample
|
||||
@ -58,14 +58,12 @@ SUBDIRS += examples/soapQQtOnline
|
||||
#need webwork - WebSupport
|
||||
#-----------------------------------------------------------------
|
||||
SUBDIRS += examples/qqtftpclient
|
||||
SUBDIRS += examples/qqthttpdownload
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
#some example project
|
||||
#maybe demo
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
SUBDIRS += demo/VegeTablesPrice
|
||||
greaterThan(QT_MAJOR_VERSION , 4):SUBDIRS += demo/VegeTablesPrice
|
||||
SUBDIRS += demo/cmdwidget
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
@ -33,7 +33,7 @@
|
||||
- QQtSerialPort 兼容QSerialPort and QextSerialPort
|
||||
- QQtSocketTcpClient、QQtSocketTcpServer、QQtSocketUdpClient、QQtSocketUdpServer
|
||||
- QQtBluetoothSocket +QQtBluetoothManager
|
||||
- QQtWebProtocolManager,支持http、ftp等主流协议,高并发传输。
|
||||
- QQtWebAccessManager,支持http、ftp等主流协议,高并发传输。
|
||||
- QQtWebSocket接口
|
||||
- 协议虚类(接口类) QQtProtocol QQtWebSocketProtocol
|
||||
- 报文虚类(接口类) QQtMessage
|
||||
|
@ -14,7 +14,7 @@ MainWindow::MainWindow ( QWidget* parent ) :
|
||||
|
||||
//ui->b0->setFixedHeight ( 50 );
|
||||
//ui->b1->setFixedHeight ( 50 );
|
||||
m_client = new QQtWebProtocolManager ( this );
|
||||
m_client = new QQtWebAccessManager ( this );
|
||||
connect ( m_client, SIGNAL ( replyFinished ( QNetworkReply* ) ),
|
||||
this, SLOT ( replyFinished ( QNetworkReply* ) ) );
|
||||
|
||||
|
@ -36,7 +36,7 @@ private slots:
|
||||
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
QQtWebProtocolManager* m_client;
|
||||
QQtWebAccessManager* m_client;
|
||||
QMap<QString, QString> m_mapVege;
|
||||
QBarSet* m_barSet0;
|
||||
QBarSet* m_barSet1;
|
||||
|
@ -3,7 +3,24 @@
|
||||
# Project created by QtCreator 2016-09-30T09:34:03
|
||||
#
|
||||
#-------------------------------------------------
|
||||
include(../qqtframe2/link_qqt_library.pri)
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = cmdwidget
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
cmdwidget.cpp \
|
||||
rlineedit.cpp
|
||||
|
||||
HEADERS += cmdwidget.h \
|
||||
rlineedit.h
|
||||
|
||||
FORMS += cmdwidget.ui
|
||||
|
||||
include($$PWD/../../examples/qqtframe2/link_qqt_library.pri)
|
||||
|
||||
############
|
||||
##install
|
||||
@ -31,19 +48,3 @@ equals(QKIT_PRIVATE, ANDROID) {
|
||||
message ($${TARGET} config $${CONFIG})
|
||||
message ($${TARGET} define $${DEFINES})
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = cmdwidget
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
cmdwidget.cpp \
|
||||
rlineedit.cpp
|
||||
|
||||
HEADERS += cmdwidget.h \
|
||||
rlineedit.h
|
||||
|
||||
FORMS += cmdwidget.ui
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "qqthttpdownloadprotocol.h"
|
||||
|
||||
QQtHttpDownloadProtocol::QQtHttpDownloadProtocol ( QObject* parent ) : QQtWebSocketProtocol ( parent )
|
||||
QQtHttpDownloadProtocol::QQtHttpDownloadProtocol(QObject* parent) : QQtWebAccessManager(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
#ifndef QQTHTTPDOWNLOADPROTOCOL_H
|
||||
#define QQTHTTPDOWNLOADPROTOCOL_H
|
||||
|
||||
#include <qqtwebsocketprotocol.h>
|
||||
#include <qqtwebprotocolmanager.h>
|
||||
#include <qqtwebaccessmanager.h>
|
||||
|
||||
class QQtHttpDownloadWebWorkSession: public QQtWebWorkSession
|
||||
class QQtHttpDownloadWebWorkSession: public QQtWebAccessSession
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtHttpDownloadWebWorkSession ( QObject* parent = 0 ) : QQtWebWorkSession ( parent ) {}
|
||||
explicit QQtHttpDownloadWebWorkSession(QObject* parent = 0) : QQtWebAccessSession(parent) {}
|
||||
virtual ~QQtHttpDownloadWebWorkSession() {}
|
||||
};
|
||||
|
||||
class QQtHttpDownloadProtocol : public QQtWebSocketProtocol
|
||||
class QQtHttpDownloadProtocol : public QQtWebAccessManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtHttpDownloadProtocol(QObject* parent = nullptr);
|
||||
virtual ~QQtHttpDownloadProtocol() {}
|
||||
|
||||
void sendRequstUrl ( QString& url ) {
|
||||
void sendRequstUrl(QString& url)
|
||||
{
|
||||
m_url = url;
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,10 @@
|
||||
#define QQTCHART_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <qqtcore.h>
|
||||
#include <qqt-local.h>
|
||||
|
||||
class QQtChart : public QWidget
|
||||
class QQTSHARED_EXPORT QQtChart : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -45,7 +45,11 @@
|
||||
#include <QMargins>
|
||||
#include <qmath.h>
|
||||
#include <limits>
|
||||
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
||||
#include <QtPrintSupport/qtprintsupportglobal.h>
|
||||
#else
|
||||
#include <QtGlobal>
|
||||
#endif
|
||||
#ifndef QT_NO_PRINTER
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
# include <qnumeric.h>
|
||||
@ -100,7 +104,8 @@ class QCPBars;
|
||||
/*!
|
||||
The QCP Namespace contains general enums and QFlags used throughout the QCustomPlot library
|
||||
*/
|
||||
namespace QCP {
|
||||
namespace QCP
|
||||
{
|
||||
/*!
|
||||
Defines the sides of a rectangular entity to which margins can be applied.
|
||||
|
||||
|
183
src/network/qqtwebaccessmanager.cpp
Normal file
183
src/network/qqtwebaccessmanager.cpp
Normal file
@ -0,0 +1,183 @@
|
||||
#include "qqtwebaccessmanager.h"
|
||||
#include "qqtcore.h"
|
||||
|
||||
|
||||
QQtWebAccessManager::QQtWebAccessManager(QObject* parent) : QNetworkAccessManager(parent)
|
||||
{
|
||||
m_listWebWorkSession.clear();
|
||||
|
||||
connect(this, SIGNAL(finished(QNetworkReply*)),
|
||||
this, SLOT(finished(QNetworkReply*)));
|
||||
|
||||
connect(this, SIGNAL(finished(QNetworkReply*)),
|
||||
this, SIGNAL(replyFinished(QNetworkReply*)));
|
||||
|
||||
connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
|
||||
this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)));
|
||||
|
||||
connect(this, SIGNAL(proxyAuthenticationRequired(QNetworkProxy, QAuthenticator*)),
|
||||
this, SLOT(proxyAuthenticationRequired(QNetworkProxy, QAuthenticator*)));
|
||||
|
||||
connect(this, SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
|
||||
this, SLOT(sslErrors(QNetworkReply*, QList<QSslError>)));
|
||||
|
||||
connect(this, SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)),
|
||||
this, SLOT(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
|
||||
|
||||
connect(this, SIGNAL(networkSessionConnected()),
|
||||
this, SLOT(networkSessionConnected()));
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::sendGetRequest(QString& strUrl)
|
||||
{
|
||||
QQtWebAccessSession* s0 = new QQtWebAccessSession(this);
|
||||
|
||||
s0->m_strUrl = strUrl;
|
||||
s0->m_pTimer = new QTimer(this);
|
||||
s0->m_pTimer->setSingleShot(true);
|
||||
s0->m_pTimer->setInterval(10000);
|
||||
connect(s0->m_pTimer, SIGNAL(timeout()),
|
||||
this, SLOT(localReplyTimeOut())); //超时信号
|
||||
|
||||
QNetworkRequest netRequest;
|
||||
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
netRequest.setUrl(QUrl(strUrl)); //地址信息
|
||||
|
||||
if (strUrl.toLower().startsWith("https")) //https请求,需ssl支持(下载openssl拷贝libeay32.dll和ssleay32.dll文件至Qt bin目录或程序运行目录)
|
||||
{
|
||||
QSslConfiguration sslConfig;
|
||||
sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
sslConfig.setProtocol(QSsl::TlsV1_1);
|
||||
netRequest.setSslConfiguration(sslConfig);
|
||||
}
|
||||
|
||||
s0->m_pNetworkReply = get(netRequest); //发起get请求
|
||||
m_listWebWorkSession.push_back(s0);
|
||||
/*下面关联信号和槽*/
|
||||
|
||||
/*下载完成后开始一阵一阵堆取数据*/
|
||||
connect(s0->m_pNetworkReply, SIGNAL(readyRead()),
|
||||
this, SLOT(localReadyRead()));
|
||||
|
||||
/*有可用数据时 */
|
||||
connect(s0->m_pNetworkReply, SIGNAL(downloadProgress(qint64, qint64)),
|
||||
this, SLOT(localUpdateDownloadProgress(qint64, qint64)));
|
||||
connect(s0->m_pNetworkReply, SIGNAL(uploadProgress(qint64, qint64)),
|
||||
this, SLOT(localUpdateUploadProgress(qint64, qint64)));
|
||||
|
||||
//ignore
|
||||
// connect ( s0->m_pNetworkReply, SIGNAL ( finished() ),
|
||||
// this, SLOT ( finished(QNetworkReply*); ) ); //请求完成信号
|
||||
|
||||
s0->m_pTimer->start();
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::sendPostRequest(QString& strUrl)
|
||||
{
|
||||
//post
|
||||
// QString strBody; //http body部分,可封装参数信息
|
||||
// QByteArray contentByteArray = strBody.toLatin1();//转成二进制
|
||||
// m_pNetworkReply = m_pNetworkManager->post(netRequest,contentByteArray);//发起post请求
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::finished(QNetworkReply* reply)
|
||||
{
|
||||
pline() << reply;
|
||||
|
||||
//clear resource
|
||||
QQtWebAccessSession* s0 = NULL;
|
||||
QListIterator<QQtWebAccessSession*> itor(m_listWebWorkSession);
|
||||
|
||||
while (itor.hasNext())
|
||||
{
|
||||
QQtWebAccessSession* s1 = itor.next();
|
||||
|
||||
if (s1->m_pNetworkReply == reply)
|
||||
{
|
||||
s0 = s1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!s0)
|
||||
return;
|
||||
|
||||
pline() << s0->m_pNetworkReply << s0->m_pTimer;
|
||||
|
||||
s0->m_pTimer->stop();
|
||||
s0->m_pNetworkReply->deleteLater();
|
||||
m_listWebWorkSession.removeOne(s0);
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::authenticationRequired(QNetworkReply* r, QAuthenticator* a)
|
||||
{
|
||||
pline() << r << a;
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::proxyAuthenticationRequired(QNetworkProxy p, QAuthenticator* a)
|
||||
{
|
||||
pline() << p.hostName() << a;
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::sslErrors(QNetworkReply* r, QList<QSslError> e)
|
||||
{
|
||||
pline() << r << e.size();
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility a)
|
||||
{
|
||||
pline() << a;
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::networkSessionConnected()
|
||||
{
|
||||
pline();
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::localReplyTimeOut()
|
||||
{
|
||||
QTimer* obj = (QTimer*) sender();
|
||||
pline() << obj;
|
||||
|
||||
QQtWebAccessSession* s0 = NULL;
|
||||
QListIterator<QQtWebAccessSession*> itor(m_listWebWorkSession);
|
||||
|
||||
while (itor.hasNext())
|
||||
{
|
||||
QQtWebAccessSession* s1 = itor.next();
|
||||
|
||||
if (s1->m_pTimer == obj)
|
||||
{
|
||||
s0 = s1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!s0)
|
||||
return;
|
||||
|
||||
emit replyTimeOut(s0->m_pNetworkReply); //请求失败
|
||||
|
||||
s0->m_pNetworkReply->deleteLater();
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::localReadyRead()
|
||||
{
|
||||
QNetworkReply* obj = (QNetworkReply*) sender();
|
||||
pline() << obj;
|
||||
emit readyRead(obj);
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::localUpdateUploadProgress(qint64 bytesSent, qint64 bytesTotal)
|
||||
{
|
||||
QNetworkReply* obj = (QNetworkReply*) sender();
|
||||
pline() << obj;
|
||||
emit updateUploadProgress(obj, bytesSent, bytesTotal);
|
||||
}
|
||||
|
||||
void QQtWebAccessManager::localUpdateDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||
{
|
||||
QNetworkReply* obj = (QNetworkReply*) sender();
|
||||
pline() << obj;
|
||||
emit updateDownloadProgress(obj, bytesReceived, bytesTotal);
|
||||
}
|
78
src/network/qqtwebaccessmanager.h
Normal file
78
src/network/qqtwebaccessmanager.h
Normal file
@ -0,0 +1,78 @@
|
||||
#ifndef QQTWEBWORKCLIENT_H
|
||||
#define QQTWEBWORKCLIENT_H
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
//import this struct will not build fail
|
||||
#include <QNetworkProxy>
|
||||
#include <QSslError>
|
||||
#include <qqt-qt.h>
|
||||
#include <qqt-local.h>
|
||||
#include <qqtcore.h>
|
||||
|
||||
class QQTSHARED_EXPORT QQtWebAccessSession : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtWebAccessSession(QObject* parent = 0) :
|
||||
QObject(parent) {}
|
||||
virtual ~QQtWebAccessSession() {}
|
||||
|
||||
QNetworkReply* m_pNetworkReply; //封装请求返回信息
|
||||
QTimer* m_pTimer; //请求超时计时器
|
||||
QString m_strUrl; //记录当前请求的url
|
||||
/**
|
||||
* @brief m_sessionName
|
||||
* talk with whom, which protocol, req content, all represented by this name;
|
||||
*/
|
||||
QString m_sessionName;
|
||||
} ;
|
||||
/**
|
||||
* @brief The QQtWebworkClient class
|
||||
* One Ftp Http 单工...
|
||||
* Multi 半双工(客户端并发,服务器序列) QNetworkAccessManager
|
||||
* Multi New Protocol 全双工 QWebSocket
|
||||
* need ssl
|
||||
* Qt team 实现了几种协议的管理,就能进行几种协议的通讯。supportedSchemes
|
||||
*/
|
||||
class QQTSHARED_EXPORT QQtWebAccessManager : public QNetworkAccessManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtWebAccessManager(QObject* parent = 0);
|
||||
|
||||
QNetworkReply* getReplyHandler(QString& strUrl) {}
|
||||
|
||||
void sendGetRequest(QString& strUrl);
|
||||
void sendPostRequest(QString& strUrl);
|
||||
|
||||
signals:
|
||||
void updateUploadProgress(QNetworkReply* reply, qint64 bytesSent, qint64 bytesTotal);
|
||||
void updateDownloadProgress(QNetworkReply* reply, qint64 bytesReceived, qint64 bytesTotal);
|
||||
//reply->readAll but maybe not all data once
|
||||
void readyRead(QNetworkReply* reply);
|
||||
//reply->readAll all data once in theory
|
||||
void replyFinished(QNetworkReply* reply);
|
||||
void replyTimeOut(QNetworkReply* reply);
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void finished(QNetworkReply* reply);
|
||||
void authenticationRequired(QNetworkReply*, QAuthenticator*);
|
||||
void proxyAuthenticationRequired(QNetworkProxy, QAuthenticator*);
|
||||
void sslErrors(QNetworkReply*, QList<QSslError>);
|
||||
void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility);
|
||||
void networkSessionConnected();
|
||||
|
||||
void localReplyTimeOut();
|
||||
void localReadyRead();
|
||||
void localUpdateUploadProgress(qint64 bytesSent, qint64 bytesTotal);
|
||||
void localUpdateDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
|
||||
private:
|
||||
|
||||
QList<QQtWebAccessSession*> m_listWebWorkSession;
|
||||
};
|
||||
|
||||
#endif // QQTWEBWORKCLIENT_H
|
@ -1,183 +0,0 @@
|
||||
#include "qqtwebprotocolmanager.h"
|
||||
#include "qqtcore.h"
|
||||
|
||||
|
||||
QQtWebProtocolManager::QQtWebProtocolManager ( QObject* parent ) : QNetworkAccessManager ( parent )
|
||||
{
|
||||
m_listWebWorkSession.clear();
|
||||
|
||||
connect ( this, SIGNAL ( finished ( QNetworkReply* ) ),
|
||||
this, SLOT ( finished ( QNetworkReply* ) ) );
|
||||
|
||||
connect ( this, SIGNAL ( finished ( QNetworkReply* ) ),
|
||||
this, SIGNAL ( replyFinished ( QNetworkReply* ) ) );
|
||||
|
||||
connect ( this, SIGNAL ( authenticationRequired ( QNetworkReply*, QAuthenticator* ) ),
|
||||
this, SLOT ( authenticationRequired ( QNetworkReply*, QAuthenticator* ) ) );
|
||||
|
||||
connect ( this, SIGNAL ( proxyAuthenticationRequired ( QNetworkProxy, QAuthenticator* ) ),
|
||||
this, SLOT ( proxyAuthenticationRequired ( QNetworkProxy, QAuthenticator* ) ) );
|
||||
|
||||
connect ( this, SIGNAL ( sslErrors ( QNetworkReply*, QList<QSslError> ) ),
|
||||
this, SLOT ( sslErrors ( QNetworkReply*, QList<QSslError> ) ) );
|
||||
|
||||
connect ( this, SIGNAL ( networkAccessibleChanged ( QNetworkAccessManager::NetworkAccessibility ) ),
|
||||
this, SLOT ( networkAccessibleChanged ( QNetworkAccessManager::NetworkAccessibility ) ) );
|
||||
|
||||
connect ( this, SIGNAL ( networkSessionConnected() ),
|
||||
this, SLOT ( networkSessionConnected() ) );
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::sendGetRequest ( QString& strUrl )
|
||||
{
|
||||
QQtWebWorkSession* s0 = new QQtWebWorkSession ( this );
|
||||
|
||||
s0->m_strUrl = strUrl;
|
||||
s0->m_pTimer = new QTimer ( this );
|
||||
s0->m_pTimer->setSingleShot ( true );
|
||||
s0->m_pTimer->setInterval ( 10000 );
|
||||
connect ( s0->m_pTimer, SIGNAL ( timeout() ),
|
||||
this, SLOT ( localReplyTimeOut() ) ); //超时信号
|
||||
|
||||
QNetworkRequest netRequest;
|
||||
netRequest.setHeader ( QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded" );
|
||||
netRequest.setUrl ( QUrl ( strUrl ) ); //地址信息
|
||||
|
||||
if ( strUrl.toLower().startsWith ( "https" ) ) //https请求,需ssl支持(下载openssl拷贝libeay32.dll和ssleay32.dll文件至Qt bin目录或程序运行目录)
|
||||
{
|
||||
QSslConfiguration sslConfig;
|
||||
sslConfig.setPeerVerifyMode ( QSslSocket::VerifyNone );
|
||||
sslConfig.setProtocol ( QSsl::TlsV1_1 );
|
||||
netRequest.setSslConfiguration ( sslConfig );
|
||||
}
|
||||
|
||||
s0->m_pNetworkReply = get ( netRequest ); //发起get请求
|
||||
m_listWebWorkSession.push_back ( s0 );
|
||||
/*下面关联信号和槽*/
|
||||
|
||||
/*下载完成后开始一阵一阵堆取数据*/
|
||||
connect ( s0->m_pNetworkReply, SIGNAL ( readyRead() ),
|
||||
this, SLOT ( localReadyRead() ) );
|
||||
|
||||
/*有可用数据时 */
|
||||
connect ( s0->m_pNetworkReply, SIGNAL ( downloadProgress ( qint64, qint64 ) ),
|
||||
this, SLOT ( localUpdateDownloadProgress ( qint64, qint64 ) ) );
|
||||
connect ( s0->m_pNetworkReply, SIGNAL ( uploadProgress ( qint64, qint64 ) ),
|
||||
this, SLOT ( localUpdateUploadProgress ( qint64, qint64 ) ) );
|
||||
|
||||
//ignore
|
||||
// connect ( s0->m_pNetworkReply, SIGNAL ( finished() ),
|
||||
// this, SLOT ( finished(QNetworkReply*); ) ); //请求完成信号
|
||||
|
||||
s0->m_pTimer->start ( );
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::sendPostRequest ( QString& strUrl )
|
||||
{
|
||||
//post
|
||||
// QString strBody; //http body部分,可封装参数信息
|
||||
// QByteArray contentByteArray = strBody.toLatin1();//转成二进制
|
||||
// m_pNetworkReply = m_pNetworkManager->post(netRequest,contentByteArray);//发起post请求
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::finished ( QNetworkReply* reply )
|
||||
{
|
||||
pline() << reply;
|
||||
|
||||
//clear resource
|
||||
QQtWebWorkSession* s0 = NULL;
|
||||
QListIterator<QQtWebWorkSession*> itor ( m_listWebWorkSession );
|
||||
|
||||
while ( itor.hasNext() )
|
||||
{
|
||||
QQtWebWorkSession* s1 = itor.next();
|
||||
|
||||
if ( s1->m_pNetworkReply == reply )
|
||||
{
|
||||
s0 = s1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !s0 )
|
||||
return;
|
||||
|
||||
pline() << s0->m_pNetworkReply << s0->m_pTimer;
|
||||
|
||||
s0->m_pTimer->stop();
|
||||
s0->m_pNetworkReply->deleteLater();
|
||||
m_listWebWorkSession.removeOne ( s0 );
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::authenticationRequired ( QNetworkReply* r, QAuthenticator* a )
|
||||
{
|
||||
pline() << r << a;
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::proxyAuthenticationRequired ( QNetworkProxy p, QAuthenticator* a )
|
||||
{
|
||||
pline() << p.hostName() << a;
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::sslErrors ( QNetworkReply* r, QList<QSslError> e )
|
||||
{
|
||||
pline() << r << e.size();
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::networkAccessibleChanged ( QNetworkAccessManager::NetworkAccessibility a )
|
||||
{
|
||||
pline() << a;
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::networkSessionConnected()
|
||||
{
|
||||
pline();
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::localReplyTimeOut()
|
||||
{
|
||||
QTimer* obj = ( QTimer* ) sender();
|
||||
pline() << obj;
|
||||
|
||||
QQtWebWorkSession* s0 = NULL;
|
||||
QListIterator<QQtWebWorkSession*> itor ( m_listWebWorkSession );
|
||||
|
||||
while ( itor.hasNext() )
|
||||
{
|
||||
QQtWebWorkSession* s1 = itor.next();
|
||||
|
||||
if ( s1->m_pTimer == obj )
|
||||
{
|
||||
s0 = s1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !s0 )
|
||||
return;
|
||||
|
||||
emit replyTimeOut ( s0->m_pNetworkReply ); //请求失败
|
||||
|
||||
s0->m_pNetworkReply->deleteLater();
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::localReadyRead()
|
||||
{
|
||||
QNetworkReply* obj = ( QNetworkReply* ) sender();
|
||||
pline() << obj;
|
||||
emit readyRead ( obj );
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::localUpdateUploadProgress ( qint64 bytesSent, qint64 bytesTotal )
|
||||
{
|
||||
QNetworkReply* obj = ( QNetworkReply* ) sender();
|
||||
pline() << obj;
|
||||
emit updateUploadProgress ( obj, bytesSent, bytesTotal );
|
||||
}
|
||||
|
||||
void QQtWebProtocolManager::localUpdateDownloadProgress ( qint64 bytesReceived, qint64 bytesTotal )
|
||||
{
|
||||
QNetworkReply* obj = ( QNetworkReply* ) sender();
|
||||
pline() << obj;
|
||||
emit updateDownloadProgress ( obj, bytesReceived, bytesTotal );
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
#ifndef QQTWEBWORKCLIENT_H
|
||||
#define QQTWEBWORKCLIENT_H
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
//import this struct will not build fail
|
||||
#include <QNetworkProxy>
|
||||
#include <QSslError>
|
||||
#include <qqt-qt.h>
|
||||
#include <qqt-local.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief The QQtWebworkClient class
|
||||
* One Ftp Http 单工...
|
||||
* Multi 半双工(客户端并发,服务器序列) QNetworkAccessManager
|
||||
* Multi New Protocol 全双工 QWebSocket
|
||||
* need ssl
|
||||
* Qt team 实现了几种协议的管理,就能进行几种协议的通讯。supportedSchemes
|
||||
*/
|
||||
class QQtWebWorkSession;
|
||||
class QQTSHARED_EXPORT QQtWebProtocolManager : public QNetworkAccessManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtWebProtocolManager ( QObject* parent = 0 );
|
||||
|
||||
QNetworkReply* getReplyHandler ( QString& strUrl ) {}
|
||||
|
||||
void sendGetRequest ( QString& strUrl );
|
||||
void sendPostRequest ( QString& strUrl );
|
||||
|
||||
signals:
|
||||
void updateUploadProgress ( QNetworkReply* reply, qint64 bytesSent, qint64 bytesTotal );
|
||||
void updateDownloadProgress ( QNetworkReply* reply, qint64 bytesReceived, qint64 bytesTotal );
|
||||
//reply->readAll but maybe not all data once
|
||||
void readyRead ( QNetworkReply* reply );
|
||||
//reply->readAll all data once in theory
|
||||
void replyFinished ( QNetworkReply* reply );
|
||||
void replyTimeOut ( QNetworkReply* reply );
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void finished ( QNetworkReply* reply );
|
||||
void authenticationRequired ( QNetworkReply*, QAuthenticator* );
|
||||
void proxyAuthenticationRequired ( QNetworkProxy, QAuthenticator* );
|
||||
void sslErrors ( QNetworkReply*, QList<QSslError> );
|
||||
void networkAccessibleChanged ( QNetworkAccessManager::NetworkAccessibility );
|
||||
void networkSessionConnected();
|
||||
|
||||
void localReplyTimeOut();
|
||||
void localReadyRead();
|
||||
void localUpdateUploadProgress ( qint64 bytesSent, qint64 bytesTotal );
|
||||
void localUpdateDownloadProgress ( qint64 bytesReceived, qint64 bytesTotal );
|
||||
|
||||
private:
|
||||
|
||||
QList<QQtWebWorkSession*> m_listWebWorkSession;
|
||||
};
|
||||
|
||||
class QQtWebWorkSession : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtWebWorkSession ( QObject* parent ) :
|
||||
QObject ( parent ) {}
|
||||
virtual ~QQtWebWorkSession() {}
|
||||
|
||||
QNetworkReply* m_pNetworkReply; //封装请求返回信息
|
||||
QTimer* m_pTimer; //请求超时计时器
|
||||
QString m_strUrl; //记录当前请求的url
|
||||
/**
|
||||
* @brief m_sessionName
|
||||
* talk with whom, which protocol, req content, all represented by this name;
|
||||
*/
|
||||
QString m_sessionName;
|
||||
} ;
|
||||
|
||||
#endif // QQTWEBWORKCLIENT_H
|
@ -183,9 +183,9 @@ DEFINES += __WEBSERVICESUPPORT__
|
||||
#One Ftp Http 单工...
|
||||
#Multi 半双工(客户端并发,服务器序列) QNetworkAccessManager
|
||||
#if you use QNetworkAccessManagerSupport , open this annotation
|
||||
DEFINES += __WEBPROTOCOLSUPPORT__
|
||||
lessThan(QT_MAJOR_VERSION, 5): DEFINES -= __WEBPROTOCOLSUPPORT__
|
||||
contains (DEFINES, __WEBPROTOCOLSUPPORT__) {
|
||||
DEFINES += __WEBACCESSSUPPORT__
|
||||
lessThan(QT_MAJOR_VERSION, 5): DEFINES -= __WEBACCESSSUPPORT__
|
||||
contains (DEFINES, __WEBACCESSSUPPORT__) {
|
||||
#QSslError not found, you need recompiler Qt4
|
||||
#TODO: QT += webkit
|
||||
}
|
||||
@ -203,6 +203,7 @@ contains (DEFINES, __WEBSOCKETSUPPORT__) {
|
||||
##################Charts Module###############################
|
||||
#if you use QQtCharts, open this annotation
|
||||
DEFINES += __QQTCHARTS__
|
||||
lessThan(QT_MAJOR_VERSION, 5):DEFINES-=__QQTCHARTS__
|
||||
#based on QtCharts, need charts module
|
||||
contains(DEFINES, __QQTCHARTS__) {
|
||||
QT += charts
|
||||
|
@ -252,11 +252,12 @@ contains(DEFINES, __WEBSERVICESUPPORT__) {
|
||||
HEADERS += \
|
||||
$$PWD/network/soap/qtsoap.h
|
||||
}
|
||||
contains (DEFINES, __WEBPROTOCOLSUPPORT__) {
|
||||
#webaccess manager
|
||||
contains (DEFINES, __WEBACCESSSUPPORT__) {
|
||||
SOURCES += \
|
||||
$$PWD/network/qqtwebprotocolmanager.cpp
|
||||
$$PWD/network/qqtwebaccessmanager.cpp
|
||||
HEADERS += \
|
||||
$$PWD/network/qqtwebprotocolmanager.h
|
||||
$$PWD/network/qqtwebaccessmanager.h
|
||||
}
|
||||
|
||||
contains (DEFINES, __WEBSOCKETSUPPORT__) {
|
||||
|
@ -4,6 +4,9 @@
|
||||
#include <GumboQuerySelection.h>
|
||||
#include <GumboQueryNode.h>
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
|
||||
void test_parser()
|
||||
{
|
||||
std::string page("<h1><a>wrong link</a><a class=\"special\"\\>some link</a></h1>");
|
||||
|
Loading…
x
Reference in New Issue
Block a user