diff options
Diffstat (limited to 'c++-qt/tests/echo')
| -rw-r--r-- | c++-qt/tests/echo/echo.pro | 15 | ||||
| -rw-r--r-- | c++-qt/tests/echo/main.cpp | 14 | ||||
| -rw-r--r-- | c++-qt/tests/echo/mainwnd.cpp | 30 | ||||
| -rw-r--r-- | c++-qt/tests/echo/mainwnd.h | 23 |
4 files changed, 82 insertions, 0 deletions
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 @@ | |||
| 1 | ###################################################################### | ||
| 2 | # Automatically generated by qmake (2.01a) Fri Apr 6 00:45:00 2012 | ||
| 3 | ###################################################################### | ||
| 4 | |||
| 5 | TEMPLATE = app | ||
| 6 | TARGET = | ||
| 7 | DEPENDPATH += . | ||
| 8 | INCLUDEPATH += . ../.. | ||
| 9 | QT += network | ||
| 10 | |||
| 11 | LIBS += -L../.. -lgats-qt | ||
| 12 | |||
| 13 | # Input | ||
| 14 | SOURCES += main.cpp mainwnd.cpp | ||
| 15 | 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 @@ | |||
| 1 | #include <QApplication> | ||
| 2 | |||
| 3 | #include "mainwnd.h" | ||
| 4 | |||
| 5 | int main( int argc, char *argv[] ) | ||
| 6 | { | ||
| 7 | QApplication app( argc, argv ); | ||
| 8 | |||
| 9 | MainWnd wnd; | ||
| 10 | wnd.show(); | ||
| 11 | |||
| 12 | return app.exec(); | ||
| 13 | } | ||
| 14 | |||
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 @@ | |||
| 1 | #include "mainwnd.h" | ||
| 2 | |||
| 3 | MainWnd::MainWnd() | ||
| 4 | { | ||
| 5 | pSrv = new QTcpServer( this ); | ||
| 6 | connect( pSrv, SIGNAL(newConnection()), this, SLOT(newConnection())); | ||
| 7 | pSrv->listen( QHostAddress::Any, 7317 ); | ||
| 8 | } | ||
| 9 | |||
| 10 | MainWnd::~MainWnd() | ||
| 11 | { | ||
| 12 | } | ||
| 13 | |||
| 14 | void MainWnd::newConnection() | ||
| 15 | { | ||
| 16 | while( pSrv->hasPendingConnections() ) | ||
| 17 | { | ||
| 18 | QTcpSocket *pSock = pSrv->nextPendingConnection(); | ||
| 19 | Gats::GatsStream *pGats = new Gats::GatsStream( *pSock ); | ||
| 20 | connect( pSock, SIGNAL(readyRead()), pGats, SLOT(readObject()) ); | ||
| 21 | connect( pGats, SIGNAL(objectRead( Gats::Object * )), | ||
| 22 | this, SLOT(objectRead( Gats::Object * ))); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | void MainWnd::objectRead( Gats::Object *pObj ) | ||
| 27 | { | ||
| 28 | ((Gats::GatsStream *)sender())->writeObject( pObj ); | ||
| 29 | delete pObj; | ||
| 30 | } | ||
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 @@ | |||
| 1 | |||
| 2 | #include <QTcpServer> | ||
| 3 | #include <QTcpSocket> | ||
| 4 | #include <QMainWindow> | ||
| 5 | |||
| 6 | #include "gats-qt/gatsstream.h" | ||
| 7 | #include "gats-qt/types.h" | ||
| 8 | |||
| 9 | class MainWnd : public QMainWindow | ||
| 10 | { | ||
| 11 | Q_OBJECT; | ||
| 12 | public: | ||
| 13 | QTcpServer *pSrv; | ||
| 14 | |||
| 15 | MainWnd(); | ||
| 16 | virtual ~MainWnd(); | ||
| 17 | |||
| 18 | public slots: | ||
| 19 | void newConnection(); | ||
| 20 | void objectRead( Gats::Object *pObj ); | ||
| 21 | |||
| 22 | signals: | ||
| 23 | }; | ||
