From 52bac339b6267aa9aaa3e2e0d02c2a62e47f83e4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 6 Apr 2012 06:57:51 +0000 Subject: Qt is tested more thoroughly, some read bugs are fixed. It also works better with qt principles. You can hook up the readyRead signal to the readObject slot on GatsStream, and connect the GatsStream objectRead signal to your own functions, and you'll be notified whenever a new gats object is read. Cool. --- c++-qt/tests/echo/echo.pro | 15 +++++++++++++++ c++-qt/tests/echo/main.cpp | 14 ++++++++++++++ c++-qt/tests/echo/mainwnd.cpp | 30 ++++++++++++++++++++++++++++++ c++-qt/tests/echo/mainwnd.h | 23 +++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 c++-qt/tests/echo/echo.pro create mode 100644 c++-qt/tests/echo/main.cpp create mode 100644 c++-qt/tests/echo/mainwnd.cpp create mode 100644 c++-qt/tests/echo/mainwnd.h (limited to 'c++-qt/tests/echo') diff --git a/c++-qt/tests/echo/echo.pro b/c++-qt/tests/echo/echo.pro new file mode 100644 index 0000000..63c741a --- /dev/null +++ b/c++-qt/tests/echo/echo.pro @@ -0,0 +1,15 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Fri Apr 6 00:45:00 2012 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . ../.. +QT += network + +LIBS += -L../.. -lgats-qt + +# Input +SOURCES += main.cpp mainwnd.cpp +HEADERS += mainwnd.h diff --git a/c++-qt/tests/echo/main.cpp b/c++-qt/tests/echo/main.cpp new file mode 100644 index 0000000..43ceae4 --- /dev/null +++ b/c++-qt/tests/echo/main.cpp @@ -0,0 +1,14 @@ +#include + +#include "mainwnd.h" + +int main( int argc, char *argv[] ) +{ + QApplication app( argc, argv ); + + MainWnd wnd; + wnd.show(); + + return app.exec(); +} + diff --git a/c++-qt/tests/echo/mainwnd.cpp b/c++-qt/tests/echo/mainwnd.cpp new file mode 100644 index 0000000..4b90421 --- /dev/null +++ b/c++-qt/tests/echo/mainwnd.cpp @@ -0,0 +1,30 @@ +#include "mainwnd.h" + +MainWnd::MainWnd() +{ + pSrv = new QTcpServer( this ); + connect( pSrv, SIGNAL(newConnection()), this, SLOT(newConnection())); + pSrv->listen( QHostAddress::Any, 7317 ); +} + +MainWnd::~MainWnd() +{ +} + +void MainWnd::newConnection() +{ + while( pSrv->hasPendingConnections() ) + { + QTcpSocket *pSock = pSrv->nextPendingConnection(); + Gats::GatsStream *pGats = new Gats::GatsStream( *pSock ); + connect( pSock, SIGNAL(readyRead()), pGats, SLOT(readObject()) ); + connect( pGats, SIGNAL(objectRead( Gats::Object * )), + this, SLOT(objectRead( Gats::Object * ))); + } +} + +void MainWnd::objectRead( Gats::Object *pObj ) +{ + ((Gats::GatsStream *)sender())->writeObject( pObj ); + delete pObj; +} diff --git a/c++-qt/tests/echo/mainwnd.h b/c++-qt/tests/echo/mainwnd.h new file mode 100644 index 0000000..0afbd6a --- /dev/null +++ b/c++-qt/tests/echo/mainwnd.h @@ -0,0 +1,23 @@ + +#include +#include +#include + +#include "gats-qt/gatsstream.h" +#include "gats-qt/types.h" + +class MainWnd : public QMainWindow +{ + Q_OBJECT; +public: + QTcpServer *pSrv; + + MainWnd(); + virtual ~MainWnd(); + +public slots: + void newConnection(); + void objectRead( Gats::Object *pObj ); + +signals: +}; -- cgit v1.2.3