mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
update http download parse qt io html
This commit is contained in:
parent
76f81a0fda
commit
760b9da8a3
12
QQt.pro
12
QQt.pro
@ -16,13 +16,15 @@ SUBDIRS = src/qqt.pro
|
||||
##QQt installed to sdk or
|
||||
##QQt is build
|
||||
##-----------------------------------------------------------------
|
||||
#SUBDIRS += examples/exquisite
|
||||
#
|
||||
SUBDIRS += examples/exquisite
|
||||
#SUBDIRS += examples/tabwidgetexamples
|
||||
#SUBDIRS += examples/qrcodeexample
|
||||
#greaterThan(QT_MAJOR_VERSION , 4):SUBDIRS += examples/qqtnetworkexample
|
||||
#SUBDIRS += examples/QtBuildTool
|
||||
#SUBDIRS += examples/QtSdkManager
|
||||
#SUBDIRS += examples/QQtInstaller
|
||||
#SUBDIRS += examples/qqtnetworkexample
|
||||
|
||||
#
|
||||
##can't support ios
|
||||
#SUBDIRS += examples/qqtprintsupportexample
|
||||
@ -40,6 +42,7 @@ SUBDIRS = src/qqt.pro
|
||||
##need bluetooth library
|
||||
#SUBDIRS += examples/qqtbluetoothfiletransferserver
|
||||
#
|
||||
|
||||
##-----------------------------------------------------------------
|
||||
##need QtSoap - WebSupport
|
||||
##-----------------------------------------------------------------
|
||||
@ -55,17 +58,18 @@ SUBDIRS = src/qqt.pro
|
||||
#
|
||||
##-----------------------------------------------------------------
|
||||
##need webaccessmanager - WebSupport
|
||||
##need GumoQuery
|
||||
##-----------------------------------------------------------------
|
||||
#SUBDIRS += examples/qqtftpclient
|
||||
#greaterThan(QT_MAJOR_VERSION, 4):SUBDIRS += examples/qqthttpdownload
|
||||
|
||||
#greaterThan(QT_MAJOR_VERSION , 4):SUBDIRS += demo/VegeTablesPrice
|
||||
#
|
||||
##-----------------------------------------------------------------
|
||||
##some example project
|
||||
##maybe demo
|
||||
##-----------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
greaterThan(QT_MAJOR_VERSION , 4):SUBDIRS += demo/VegeTablesPrice
|
||||
#SUBDIRS += demo/cmdwidget
|
||||
#
|
||||
##-----------------------------------------------------------------
|
||||
|
@ -1,14 +1,41 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <qqtbluetoothmanager.h>
|
||||
#include <qqtcore.h>
|
||||
QQtBluetoothManager* manager = NULL;
|
||||
|
||||
MainWindow::MainWindow ( QWidget* parent ) :
|
||||
QMainWindow ( parent ),
|
||||
ui ( new Ui::MainWindow )
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
// bluetooth example
|
||||
manager = QQtBluetoothManager::Instance ( this );
|
||||
connect ( manager, SIGNAL ( addDevice ( QBluetoothDeviceInfo ) ), this, SLOT ( addDevice ( QBluetoothDeviceInfo ) ) );
|
||||
connect ( manager, SIGNAL ( addService ( QBluetoothServiceInfo ) ), this,
|
||||
SLOT ( addService ( QBluetoothServiceInfo ) ) );
|
||||
ui->lw0->addItem ( manager->address().toString() );
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_btnRefresh_clicked()
|
||||
{
|
||||
ui->lw1->clear();
|
||||
manager->refresh();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::addDevice ( QBluetoothDeviceInfo s )
|
||||
{
|
||||
ui->lw1->addItem ( s.address().toString() );
|
||||
}
|
||||
|
||||
void MainWindow::addService ( QBluetoothServiceInfo s )
|
||||
{
|
||||
pline() << s.serviceClassUuids();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <qqtbluetoothmanager.h>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@ -15,6 +16,14 @@ public:
|
||||
explicit MainWindow ( QWidget* parent = 0 );
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
void addDevice ( QBluetoothDeviceInfo );
|
||||
void addService ( QBluetoothServiceInfo );
|
||||
|
||||
|
||||
private slots:
|
||||
void on_btnRefresh_clicked();
|
||||
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
};
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
@ -12,10 +13,95 @@
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget" />
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Bluetooth</string>
|
||||
</attribute>
|
||||
<widget class="QListWidget" name="lw0">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>60</y>
|
||||
<width>161</width>
|
||||
<height>351</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<layoutDefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>20</y>
|
||||
<width>60</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Local:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="lw1">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>60</y>
|
||||
<width>221</width>
|
||||
<height>341</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>20</y>
|
||||
<width>60</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remote:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="lw2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>550</x>
|
||||
<y>60</y>
|
||||
<width>201</width>
|
||||
<height>341</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btnRefresh">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>540</x>
|
||||
<y>10</y>
|
||||
<width>113</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Refresh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -3,11 +3,15 @@
|
||||
|
||||
#include "qqtobjectfactory.h"
|
||||
#include "qqtcore.h"
|
||||
#include "qqthttpdownloadmanager.h"
|
||||
#include "qqtapplication.h"
|
||||
#include "qqtqtiowebpageparser.h"
|
||||
|
||||
int main ( int argc, char* argv[] )
|
||||
{
|
||||
QApplication a ( argc, argv );
|
||||
QQtApplication a ( argc, argv );
|
||||
|
||||
/*
|
||||
QQtWidgetFactory::registerObject<QPushButton>();
|
||||
QObject* obj = QQtWidgetFactory::createObject ( "QPushButton" );
|
||||
pline() << obj->inherits ( "QWidget" );
|
||||
@ -16,10 +20,13 @@ int main ( int argc, char* argv[] )
|
||||
obj->setObjectName ( "bbb" );
|
||||
pline() << obj->objectName();
|
||||
QQtObjectParcel::registerObject ( obj );
|
||||
*/
|
||||
|
||||
QQtQtIOWebPageParser webparser;
|
||||
webparser.sendRequest ( );
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
//MainWindow w;
|
||||
//w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "qqtqtiowebpageparser.h"
|
||||
|
||||
MainWindow::MainWindow ( QWidget* parent ) :
|
||||
QMainWindow ( parent ),
|
||||
ui ( new Ui::MainWindow )
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
m_webpageparser = new QQtQtIOWebPageParser ( this );
|
||||
connect ( m_webpageparser, SIGNAL ( replyFinished ( QQtWebAccessSession* ) ),
|
||||
this, SLOT ( replyFinished ( QQtWebAccessSession* ) ) );
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <qqtqtiowebpageparser.h>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@ -17,6 +18,7 @@ public:
|
||||
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
QQtQtIOWebPageParser* m_webpageparser;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
@ -14,8 +15,7 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget"/>
|
||||
</widget>
|
||||
<layoutDefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -26,11 +26,13 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
qqthttpdownloadmanager.cpp
|
||||
qqthttpdownloadmanager.cpp \
|
||||
qqtqtiowebpageparser.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
qqthttpdownloadmanager.h
|
||||
qqthttpdownloadmanager.h \
|
||||
qqtqtiowebpageparser.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
@ -2,5 +2,18 @@
|
||||
|
||||
QQtHttpDownloadManager::QQtHttpDownloadManager ( QObject* parent ) : QQtWebAccessManager ( parent )
|
||||
{
|
||||
|
||||
QFile file ( "/Users/abel/Develop/c2-test/aa" );
|
||||
file.open ( QFile::Truncate | QFile::WriteOnly );
|
||||
file.close();
|
||||
}
|
||||
|
||||
void QQtHttpDownloadManager::replyReadyRead ( QQtWebAccessSession* session )
|
||||
{
|
||||
pline() << session->getWebAccessReply()->url();
|
||||
QByteArray data = session->getWebAccessReply()->readAll();
|
||||
pline() << data;
|
||||
QFile file ( "/Users/abel/Develop/c2-test/aa" );
|
||||
file.open ( QFile::Append );
|
||||
file.write ( data );
|
||||
file.close();
|
||||
}
|
||||
|
@ -18,12 +18,21 @@ public:
|
||||
explicit QQtHttpDownloadManager ( QObject* parent = nullptr );
|
||||
virtual ~QQtHttpDownloadManager() {}
|
||||
|
||||
void sendRequest ( QString strUrl ) {
|
||||
QQtHttpDownloadWebWorkSession* session = new QQtHttpDownloadWebWorkSession ( this );
|
||||
session->setWebAccessUrl ( strUrl );
|
||||
session->setWebAccessSessionName ( QUuid::createUuid().toString() );
|
||||
getWebAccessSessionManager()->addWebAccessSession ( session );
|
||||
sendGetRequest ( session );
|
||||
connect ( this, SIGNAL ( readyRead ( QQtWebAccessSession* ) ),
|
||||
this, SLOT ( replyReadyRead ( QQtWebAccessSession* ) ) );
|
||||
}
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
//void replyReadyRead ( QNetworkReply* reply );
|
||||
void replyReadyRead ( QQtWebAccessSession* session );
|
||||
private:
|
||||
};
|
||||
|
||||
|
184
examples/qqthttpdownload/qqtqtiowebpageparser.cpp
Normal file
184
examples/qqthttpdownload/qqtqtiowebpageparser.cpp
Normal file
@ -0,0 +1,184 @@
|
||||
#include "qqtqtiowebpageparser.h"
|
||||
#include <GumboQueryDocument.h>
|
||||
#include <GumboQuerySelection.h>
|
||||
#include <GumboQueryNode.h>
|
||||
#include <QStringList>
|
||||
#include <QTextCodec>
|
||||
#include <QDomDocument>
|
||||
/**
|
||||
* @brief QQtQtIOWebPageParser::QQtQtIOWebPageParser
|
||||
* bad xml
|
||||
* @param parent
|
||||
*/
|
||||
QQtQtIOWebPageParser::QQtQtIOWebPageParser ( QObject* parent ) : QQtWebAccessManager ( parent )
|
||||
{
|
||||
m_baseUrl = "http://download.qt.io/official_releases/qt/";
|
||||
m_xmlfile = "/Users/abel/Develop/c2-test/cc.xml";
|
||||
connect ( this, SIGNAL ( replyFinished ( QQtWebAccessSession* ) ),
|
||||
this, SLOT ( replyFinished ( QQtWebAccessSession* ) ) );
|
||||
|
||||
QTimer* timer = new QTimer();
|
||||
timer->setSingleShot ( true );
|
||||
timer->setInterval ( 10000 );
|
||||
connect ( timer, &QTimer::timeout,
|
||||
[this]
|
||||
{
|
||||
QFile file ( m_xmlfile );
|
||||
file.open ( QFile::Append );
|
||||
QTextStream stream ( &file );
|
||||
m_doc.save ( stream, 0 );
|
||||
file.close();
|
||||
pline() << m_doc.childNodes().at ( 0 ).nodeValue();
|
||||
pline() << "save ok";
|
||||
} );
|
||||
timer->start();
|
||||
}
|
||||
|
||||
void QQtQtIOWebPageParser::sendRequest ( QString url1, QString url2 )
|
||||
{
|
||||
if ( url1 == "" && url2 == "" )
|
||||
{
|
||||
m_doc.clear();
|
||||
m_doc.createElement ( "Qt version list" );
|
||||
}
|
||||
|
||||
QString strUrl = QString ( "%1%2%3" ).arg ( m_baseUrl ).arg ( url1 ).arg ( url2 );
|
||||
|
||||
QQtQtIOWebUrlSession* session = new QQtQtIOWebUrlSession ( this );
|
||||
session->url1 = url1;
|
||||
session->url2 = url2;
|
||||
session->setWebAccessUrl ( strUrl );
|
||||
session->setWebAccessSessionName ( QUuid::createUuid().toString() );
|
||||
getWebAccessSessionManager()->addWebAccessSession ( session );
|
||||
sendGetRequest ( session );
|
||||
}
|
||||
|
||||
void QQtQtIOWebPageParser::replyFinished ( QQtWebAccessSession* s0 )
|
||||
{
|
||||
QQtQtIOWebUrlSession* session = ( QQtQtIOWebUrlSession* ) s0;
|
||||
QNetworkReply* reply = session->getWebAccessReply();
|
||||
//pline() << reply->readAll();
|
||||
pline() << reply->url();
|
||||
int nHttpCode = reply->attribute ( QNetworkRequest::HttpStatusCodeAttribute ).toInt(); //http返回码
|
||||
|
||||
if ( nHttpCode == 200 ) //成功
|
||||
{
|
||||
pline() << "success";
|
||||
}
|
||||
else
|
||||
{
|
||||
pline() << "fail";
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray resultContent = reply->readAll();
|
||||
//pline() << QString ( resultContent );
|
||||
QString result1 = resultContent;
|
||||
//pline() << result1.toLatin1().constData();
|
||||
pline() << QTextCodec::codecForHtml ( resultContent )->name();
|
||||
|
||||
/*用页面源文件的编码来进行解码 GB2312 or UTF-8*/
|
||||
QTextCodec* pCodec = QTextCodec::codecForName ( "GBK" );
|
||||
QString strResult = pCodec->toUnicode ( resultContent );
|
||||
//pline() << strResult;
|
||||
|
||||
QTextCodec* pCodec2 = QTextCodec::codecForName ( "UTF-8" );
|
||||
QByteArray resultContent2 = pCodec2->fromUnicode ( strResult );
|
||||
QString result2 = resultContent2;
|
||||
//pline() << result2;
|
||||
|
||||
pline() << QTextCodec::codecForLocale()->name();
|
||||
|
||||
//before </td> + /n
|
||||
result2.replace ( "</td>", "\n</td>" );
|
||||
result2.replace ( "</a>", "\n</a>" );
|
||||
result2.replace ( "</th>", "\n</th>" );
|
||||
|
||||
GumboQueryDocument doc;
|
||||
doc.parse ( result2.toLocal8Bit().constData() );
|
||||
GumboQuerySelection s = doc.find ( "table" );
|
||||
pline() << "node num:" << s.nodeNum();
|
||||
|
||||
GumboQueryNode pNode = s.nodeAt ( 0 );
|
||||
QString items = QString::fromStdString ( pNode.text() );
|
||||
qDebug() << items;
|
||||
|
||||
QStringList itemList = items.split ( "\n", QString::SkipEmptyParts );
|
||||
|
||||
for ( int i = 0; i < itemList.count(); i++ )
|
||||
{
|
||||
QString txt = itemList.at ( i );
|
||||
qDebug() << txt;
|
||||
/*
|
||||
txt = txt.trimmed();
|
||||
|
||||
if ( txt.isEmpty() )
|
||||
{
|
||||
itemList.removeAt ( i );
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
itemList[i] = txt;
|
||||
*/
|
||||
}
|
||||
|
||||
QString url1 = session->url1;
|
||||
QString url2 = session->url2;
|
||||
|
||||
|
||||
for ( int i = 0; i < itemList.count(); i++ )
|
||||
{
|
||||
/*获取第一列*/
|
||||
if ( i % 4 == 0 )
|
||||
{
|
||||
/*在根目录的时候 第一层目录 qt/*/
|
||||
if ( url1 == "" )
|
||||
{
|
||||
QString item = itemList.at ( i );
|
||||
|
||||
/*是个子目录 5.9*/
|
||||
if ( item.endsWith ( '/' ) )
|
||||
{
|
||||
QDomNode node;
|
||||
node.setNodeValue ( item );
|
||||
m_doc.appendChild ( node );
|
||||
sendRequest ( item );
|
||||
}
|
||||
}
|
||||
/*进入第二层目录 e.g. 5.9*/
|
||||
else if ( url2 == "" )
|
||||
{
|
||||
QString item = itemList.at ( i );
|
||||
|
||||
/*是个子目录 5.9.1*/
|
||||
if ( item.endsWith ( '/' ) )
|
||||
{
|
||||
|
||||
QDomNodeList dl = m_doc.childNodes();
|
||||
int j = 0;
|
||||
|
||||
for ( j = 0; j < dl.count(); j++ )
|
||||
{
|
||||
if ( dl.at ( j ).nodeValue() == url1 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QDomNode node ;
|
||||
node.setNodeValue ( item );
|
||||
dl.at ( j ).appendChild ( node );
|
||||
//url1 url2
|
||||
sendRequest ( url1, item );
|
||||
}
|
||||
}
|
||||
/*最后一层目录*/
|
||||
else
|
||||
{
|
||||
qDebug() << itemList[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
42
examples/qqthttpdownload/qqtqtiowebpageparser.h
Normal file
42
examples/qqthttpdownload/qqtqtiowebpageparser.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef QQTQTIOWEBPROTOCOL_H
|
||||
#define QQTQTIOWEBPROTOCOL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <qqtwebaccessmanager.h>
|
||||
#include <QDomDocument>
|
||||
|
||||
class QQtQtIOWebUrlSession: public QQtWebAccessSession
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtQtIOWebUrlSession ( QObject* parent = 0 ) :
|
||||
QQtWebAccessSession ( parent ) {
|
||||
url1 = "";
|
||||
url2 = "";
|
||||
}
|
||||
virtual ~QQtQtIOWebUrlSession() {}
|
||||
|
||||
QString url1;
|
||||
QString url2;
|
||||
};
|
||||
|
||||
class QQtQtIOWebPageParser : public QQtWebAccessManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtQtIOWebPageParser ( QObject* parent = nullptr );
|
||||
|
||||
void sendRequest ( QString url1 = "", QString url2 = "" );
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
private slots:
|
||||
void replyFinished ( QQtWebAccessSession* session );
|
||||
private:
|
||||
QString m_baseUrl;
|
||||
QString m_xmlfile;
|
||||
QDomDocument m_doc;
|
||||
};
|
||||
|
||||
#endif // QQTQTIOWEBPROTOCOL_H
|
@ -1,43 +1,19 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <qqtbluetoothmanager.h>
|
||||
#include <qqtcore.h>
|
||||
QQtBluetoothManager* manager = NULL;
|
||||
|
||||
MainWindow::MainWindow ( QWidget* parent ) :
|
||||
QMainWindow ( parent ),
|
||||
ui ( new Ui::MainWindow )
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
// bluetooth example
|
||||
// serialport example
|
||||
// tcpsocket example
|
||||
// websocket?
|
||||
//
|
||||
manager = QQtBluetoothManager::Instance(this);
|
||||
connect(manager, SIGNAL(addDevice(QBluetoothDeviceInfo)), this, SLOT(addDevice(QBluetoothDeviceInfo)));
|
||||
connect(manager, SIGNAL(addService(QBluetoothServiceInfo)), this, SLOT(addService(QBluetoothServiceInfo)));
|
||||
ui->lw0->addItem(manager->address().toString());
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::addDevice(QBluetoothDeviceInfo s)
|
||||
{
|
||||
ui->lw1->addItem(s.address().toString());
|
||||
}
|
||||
|
||||
void MainWindow::addService(QBluetoothServiceInfo s)
|
||||
{
|
||||
pline() << s.serviceClassUuids();
|
||||
}
|
||||
|
||||
void MainWindow::on_btnRefresh_clicked()
|
||||
{
|
||||
ui->lw1->clear();
|
||||
manager->refresh();
|
||||
}
|
||||
|
@ -2,10 +2,8 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <qqtbluetoothmanager.h>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
@ -17,14 +15,6 @@ public:
|
||||
explicit MainWindow ( QWidget* parent = 0 );
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
void addDevice(QBluetoothDeviceInfo);
|
||||
void addService(QBluetoothServiceInfo);
|
||||
|
||||
|
||||
private slots:
|
||||
void on_btnRefresh_clicked();
|
||||
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
};
|
||||
|
@ -14,91 +14,7 @@
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Bluetooth</string>
|
||||
</attribute>
|
||||
<widget class="QListWidget" name="lw0">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>60</y>
|
||||
<width>161</width>
|
||||
<height>351</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>20</y>
|
||||
<width>60</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Local:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="lw1">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>60</y>
|
||||
<width>221</width>
|
||||
<height>341</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>20</y>
|
||||
<width>60</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remote:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="lw2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>550</x>
|
||||
<y>60</y>
|
||||
<width>201</width>
|
||||
<height>341</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btnRefresh">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>540</x>
|
||||
<y>10</y>
|
||||
<width>113</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Refresh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout"/>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
|
@ -65,7 +65,7 @@ void QQtWebAccessManager::sendGetRequest ( QQtWebAccessSession* session )
|
||||
timer->start();
|
||||
}
|
||||
|
||||
QQtWebAccessSession* QQtWebAccessManager::sendGetRequest ( QString& strUrl )
|
||||
QQtWebAccessSession* QQtWebAccessManager::sendGetRequest ( QString strUrl )
|
||||
{
|
||||
QQtWebAccessSession* session = manager->newWebAccessSession();
|
||||
session->setWebAccessUrl ( strUrl );
|
||||
@ -87,7 +87,7 @@ QQtWebAccessSession* QQtWebAccessManager::sendGetRequests ( QList<QNetworkReques
|
||||
|
||||
}
|
||||
|
||||
QQtWebAccessSession* QQtWebAccessManager::sendPostRequest ( QString& strUrl )
|
||||
QQtWebAccessSession* QQtWebAccessManager::sendPostRequest ( QString strUrl )
|
||||
{
|
||||
//post
|
||||
// QString strBody; //http body部分,可封装参数信息
|
||||
|
@ -139,6 +139,10 @@ class QQTSHARED_EXPORT QQtWebAccessManager : public QNetworkAccessManager
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQtWebAccessManager ( QObject* parent = 0 );
|
||||
|
||||
QQtWebAccessSessionManager* getWebAccessSessionManager() {
|
||||
return manager;
|
||||
}
|
||||
/**
|
||||
* @brief sendGetRequest
|
||||
* use for custom session;
|
||||
@ -146,12 +150,12 @@ public:
|
||||
*/
|
||||
void sendGetRequest ( QQtWebAccessSession* session );
|
||||
|
||||
QQtWebAccessSession* sendGetRequest ( QString& strUrl );
|
||||
QQtWebAccessSession* sendGetRequest ( QString strUrl );
|
||||
QQtWebAccessSession* sendGetRequests ( QStringList& strUrls );
|
||||
QQtWebAccessSession* sendGetRequest ( QNetworkRequest& netRequest );
|
||||
QQtWebAccessSession* sendGetRequests ( QList<QNetworkRequest*>& netRequests );
|
||||
|
||||
QQtWebAccessSession* sendPostRequest ( QString& strUrl );
|
||||
QQtWebAccessSession* sendPostRequest ( QString strUrl );
|
||||
|
||||
signals:
|
||||
void updateUploadProgress ( QQtWebAccessSession* session, qint64 bytesSent, qint64 bytesTotal );
|
||||
|
Loading…
x
Reference in New Issue
Block a user