diff --git a/QQt.pro b/QQt.pro index c1f20bdb..bb7cc8b8 100644 --- a/QQt.pro +++ b/QQt.pro @@ -24,7 +24,8 @@ SUBDIRS = src/qqt.pro #SUBDIRS += examples/qrcodeexample #SUBDIRS += examples/qqtnetworkexample #udp 嵌入式linux,Qt编译了udp后支持 -#SUBDIRS += examples/qqtudpexample +# +greaterThan(QT_MAJOR_VERSION , 4):SUBDIRS += examples/qqtudpexample #SUBDIRS += examples/qqtchartexample # # @@ -48,7 +49,7 @@ SUBDIRS = src/qqt.pro #SUBDIRS += test/qqtdicttest2 #SUBDIRS += test/consoletest # -SUBDIRS += test/voicetest +greaterThan(QT_MAJOR_VERSION , 4):SUBDIRS += test/voicetest #!contains(QKIT_PRIVATE, iOS|iOSSimulator){ # SUBDIRS += test/cmdwidget diff --git a/src/frame/qqtwifidbwidget.cpp b/src/frame/qqtwifidbwidget.cpp index 763e8e51..8c7fa286 100644 --- a/src/frame/qqtwifidbwidget.cpp +++ b/src/frame/qqtwifidbwidget.cpp @@ -1,21 +1,22 @@ -#include "qqtwifidbwidget.h" +#include "qqtwifidbwidget.h" -QQtWifiDBWidget::QQtWifiDBWidget(QWidget* parent) : QQtWidget(parent) +QQtWifiDBWidget::QQtWifiDBWidget ( QWidget* parent ) : QQtWidget ( parent ) { } -void QQtWifiDBWidget::setDbPixMap(QQtWifiDBWidget::DB_STAT s, QString pixname) +void QQtWifiDBWidget::setDbPixMap ( QQtWifiDBWidget::DB_STAT s, const QString& pixname ) { - if (s < Db_S0 || s >= Db_SMax) + if ( s < Db_S0 || s >= Db_SMax ) return; pic[s] = pixname; } -void QQtWifiDBWidget::setDB(QQtWifiDBWidget::DB_STAT s) +void QQtWifiDBWidget::setDB ( QQtWifiDBWidget::DB_STAT s ) { - if (s < Db_S0 || s >= Db_SMax) + if ( s < Db_S0 || s >= Db_SMax ) return; - setPixmap(pic[s]); + + setPixmap ( pic[s] ); } diff --git a/src/frame/qqtwifidbwidget.h b/src/frame/qqtwifidbwidget.h index 03e01021..dd23eaa7 100644 --- a/src/frame/qqtwifidbwidget.h +++ b/src/frame/qqtwifidbwidget.h @@ -1,4 +1,4 @@ -#ifndef QQTWIFIDBWIDGET_H +#ifndef QQTWIFIDBWIDGET_H #define QQTWIFIDBWIDGET_H #include @@ -26,7 +26,7 @@ public: virtual ~QQtWifiDBWidget() {} void setDB ( DB_STAT s ); - void setDbPixMap ( DB_STAT s, QString pixname ); + void setDbPixMap ( DB_STAT s, const QString& pixname ); signals: diff --git a/src/network/qqtsocketudpclient.cpp b/src/network/qqtsocketudpclient.cpp index 2dbcb8a7..41e3cc80 100644 --- a/src/network/qqtsocketudpclient.cpp +++ b/src/network/qqtsocketudpclient.cpp @@ -31,10 +31,6 @@ void QQtSocketUdpClient::installProtocol ( QQtUdpProtocol* stack ) m_protocol = stack; connect ( m_protocol, SIGNAL ( writeDatagram ( QByteArray, QHostAddress, quint16 ) ), this, SLOT ( slotWriteDatagram ( QByteArray, QHostAddress, quint16 ) ) ); -#if QT_VERSION > QT_VERSION_CHECK(5,0,0) - connect ( m_protocol, SIGNAL ( writeDatagram ( const QNetworkDatagram& ) ), - this, SLOT ( slotWriteDatagram ( const QNetworkDatagram& ) ) ); -#endif } void QQtSocketUdpClient::uninstallProtocol ( QQtUdpProtocol* stack ) @@ -46,10 +42,6 @@ void QQtSocketUdpClient::uninstallProtocol ( QQtUdpProtocol* stack ) disconnect ( m_protocol, SIGNAL ( writeDatagram ( QByteArray, QHostAddress, quint16 ) ), this, SLOT ( slotWriteDatagram ( QByteArray, QHostAddress, quint16 ) ) ); -#if QT_VERSION > QT_VERSION_CHECK(5,0,0) - disconnect ( m_protocol, SIGNAL ( writeDatagram ( const QNetworkDatagram& ) ), - this, SLOT ( slotWriteDatagram ( const QNetworkDatagram& ) ) ); -#endif m_protocol = NULL; } @@ -144,9 +136,14 @@ void QQtSocketUdpClient::updateProgress ( qint64 bytes ) //pline() << bytes; } +qint64 QQtSocketUdpClient::slotWriteDatagram ( const QByteArray& datagram, const QHostAddress& host, quint16 port ) +{ + return writeDatagram ( datagram, host, port ); +} + void QQtSocketUdpClient::readyReadData() { - /*为什么用while?*/ //Qt4 没有那么高级的一次性读取的接口 + /*为什么用while?*/ //Qt4 没有那么高级的一次性读取的接口?有 while ( hasPendingDatagrams() ) { QByteArray bytes; @@ -154,7 +151,24 @@ void QQtSocketUdpClient::readyReadData() QHostAddress host; quint16 port; +#if QT_VERSION > QT_VERSION_CHECK(5,0,0) + /*能够一次收够一条报文?测试的能。*/ + QNetworkDatagram datagram = receiveDatagram(); + /*由于添加了兼容Qt4的代码,以上注释起来。*/ + + /*数据无意义 "" -1 在此设置*/ + datagram.setDestination ( this->localAddress(), this->localPort() ); + //pline() << "udp sender:" << datagram.senderAddress() << datagram.senderPort(); + //pline() << "udp receiver:" << datagram.destinationAddress() << datagram.destinationPort(); + m_protocol->translator ( datagram ); + + bytes = datagram.data(); + host = datagram.senderAddress(); + port = datagram.senderPort(); + m_protocol->translator ( bytes, host, port ); +#else qint64 size = pendingDatagramSize(); + //pline() << "udp new msg size:" << size; //这里的buf用完, 已经释放。 char* data = new char[size + 1](); qint64 len = readDatagram ( data, size, &host, &port ); @@ -163,22 +177,8 @@ void QQtSocketUdpClient::readyReadData() delete[] data; m_protocol->translator ( bytes, host, port ); - -#if QT_VERSION > QT_VERSION_CHECK(5,0,0) - /*能够一次收够一条报文?测试的能。*/ - QNetworkDatagram datagram; - //datagrame = receiveDatagram(); - /*由于添加了兼容Qt4的代码,以上注释起来。*/ - datagram.setData ( bytes ); - datagram.setSender ( host, port ); - - /*数据无意义 "" -1 在此设置*/ - datagram.setDestination ( this->localAddress(), this->localPort() ); - //pline() << "udp sender:" << datagram.senderAddress() << datagram.senderPort(); - //pline() << "udp receiver:" << datagram.destinationAddress() << datagram.destinationPort(); - //pline() << "udp new msg size:" << size; - m_protocol->translator ( datagram ); #endif + } } diff --git a/src/network/qqtsocketudpclient.h b/src/network/qqtsocketudpclient.h index 315d2db8..6f178889 100644 --- a/src/network/qqtsocketudpclient.h +++ b/src/network/qqtsocketudpclient.h @@ -42,15 +42,9 @@ private slots: void updateProgress ( qint64 bytes ); //如果有一个同名的槽,参数不同,并且被用宏控制起来,Qt编译不过。 //Qt的元对象系统,解析信号和槽函数,不支持宏。 + //QtUdpSocket,writeDatagram不是个槽。 qint64 slotWriteDatagram ( const QByteArray& datagram, - const QHostAddress& host, quint16 port ) { - return writeDatagram ( datagram, host, port ); - } -#if QT_VERSION > QT_VERSION_CHECK(5,0,0) - qint64 slotWriteDatagram ( const QNetworkDatagram& datagram ) { - return writeDatagram ( datagram ); - } -#endif + const QHostAddress& host, quint16 port ); private: QQtUdpProtocol* m_protocol; diff --git a/src/network/qqtudpprotocol.h b/src/network/qqtudpprotocol.h index bd4d8da9..f0601682 100644 --- a/src/network/qqtudpprotocol.h +++ b/src/network/qqtudpprotocol.h @@ -21,16 +21,18 @@ public: } virtual ~QQtUdpProtocol() {} -signals: - qint64 writeDatagram ( const QByteArray& datagram, - const QHostAddress& host, quint16 port ); #if QT_VERSION > QT_VERSION_CHECK(5,0,0) qint64 writeDatagram ( const QNetworkDatagram& datagram ) { //emit writeDatagram(); } #endif +signals: + qint64 writeDatagram ( const QByteArray& datagram, + const QHostAddress& host, quint16 port ); + public slots: + protected: /** * @brief 语义解析器 @@ -42,13 +44,17 @@ protected: const QHostAddress& host, quint16 port ) { return 0; } + /* + * 这两个dispatcher,任选其一重写。 + */ #if QT_VERSION > QT_VERSION_CHECK(5,0,0) inline virtual bool dispatcher ( const QNetworkDatagram& ) { return 0; } #endif + public: /** * @brief 协议处理器 - * @brief 这个处理器是给QQtSocketUdpSocket用的,不是给客户用的。 + * @brief 这个处理器是给QQtSocketUdpSocket用的,不需要用户管理。 * @param Qt通讯口readAll()读到的bytes * @return */ diff --git a/src/widgets/qqtwidget.cpp b/src/widgets/qqtwidget.cpp index 8619c098..57add431 100644 --- a/src/widgets/qqtwidget.cpp +++ b/src/widgets/qqtwidget.cpp @@ -1,4 +1,4 @@ -#include "qqtwidget.h" +#include "qqtwidget.h" #include #include "qqtcore.h" diff --git a/src/widgets/qqtwidget.h b/src/widgets/qqtwidget.h index fae6c28e..eece1ab5 100644 --- a/src/widgets/qqtwidget.h +++ b/src/widgets/qqtwidget.h @@ -1,4 +1,4 @@ -#ifndef QQTWIDGET_H +#ifndef QQTWIDGET_H #define QQTWIDGET_H #include