second test
This commit is contained in:
8
AlienDefender-readme.txt
Normal file
8
AlienDefender-readme.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
hello
|
||||||
|
this is the source code of wavetrace(base part of game)
|
||||||
|
to compilling this code you must have QT4 library and gcc compiller
|
||||||
|
to make this project you cad do:
|
||||||
|
$ qmake -project
|
||||||
|
$ qmake
|
||||||
|
$ make
|
||||||
|
or open the .pro file in Qt-Creator and run aplication.
|
||||||
30
Makefile
30
Makefile
@@ -1,6 +1,6 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
# Makefile for building: wavetrace
|
# Makefile for building: wavetrace
|
||||||
# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ???. 29 18:07:48 2009
|
# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 2 15:18:59 2009
|
||||||
# Project: wavetrace.pro
|
# Project: wavetrace.pro
|
||||||
# Template: app
|
# Template: app
|
||||||
# Command: /usr/bin/qmake -Wall -spec ../../../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile wavetrace.pro
|
# Command: /usr/bin/qmake -Wall -spec ../../../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile wavetrace.pro
|
||||||
@@ -46,13 +46,17 @@ SOURCES = main.cpp \
|
|||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
adpainter.cpp \
|
adpainter.cpp \
|
||||||
aliens.cpp \
|
aliens.cpp \
|
||||||
towers.cpp moc_mainwindow.cpp
|
udpsender.cpp \
|
||||||
|
towers.cpp moc_mainwindow.cpp \
|
||||||
|
moc_udpsender.cpp
|
||||||
OBJECTS = main.o \
|
OBJECTS = main.o \
|
||||||
mainwindow.o \
|
mainwindow.o \
|
||||||
adpainter.o \
|
adpainter.o \
|
||||||
aliens.o \
|
aliens.o \
|
||||||
|
udpsender.o \
|
||||||
towers.o \
|
towers.o \
|
||||||
moc_mainwindow.o
|
moc_mainwindow.o \
|
||||||
|
moc_udpsender.o
|
||||||
DIST = ../../../../share/qt4/mkspecs/common/g++.conf \
|
DIST = ../../../../share/qt4/mkspecs/common/g++.conf \
|
||||||
../../../../share/qt4/mkspecs/common/unix.conf \
|
../../../../share/qt4/mkspecs/common/unix.conf \
|
||||||
../../../../share/qt4/mkspecs/common/linux.conf \
|
../../../../share/qt4/mkspecs/common/linux.conf \
|
||||||
@@ -159,7 +163,7 @@ qmake: FORCE
|
|||||||
|
|
||||||
dist:
|
dist:
|
||||||
@$(CHK_DIR_EXISTS) .tmp/wavetrace1.0.0 || $(MKDIR) .tmp/wavetrace1.0.0
|
@$(CHK_DIR_EXISTS) .tmp/wavetrace1.0.0 || $(MKDIR) .tmp/wavetrace1.0.0
|
||||||
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents mainwindow.h adpainter.h aliens.h basestruct.h towers.h .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp adpainter.cpp aliens.cpp towers.cpp .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents mainwindow.ui .tmp/wavetrace1.0.0/ && (cd `dirname .tmp/wavetrace1.0.0` && $(TAR) wavetrace1.0.0.tar wavetrace1.0.0 && $(COMPRESS) wavetrace1.0.0.tar) && $(MOVE) `dirname .tmp/wavetrace1.0.0`/wavetrace1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/wavetrace1.0.0
|
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents mainwindow.h adpainter.h aliens.h basestruct.h udpsender.h towers.h .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp adpainter.cpp aliens.cpp udpsender.cpp towers.cpp .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents mainwindow.ui .tmp/wavetrace1.0.0/ && (cd `dirname .tmp/wavetrace1.0.0` && $(TAR) wavetrace1.0.0.tar wavetrace1.0.0 && $(COMPRESS) wavetrace1.0.0.tar) && $(MOVE) `dirname .tmp/wavetrace1.0.0`/wavetrace1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/wavetrace1.0.0
|
||||||
|
|
||||||
|
|
||||||
clean:compiler_clean
|
clean:compiler_clean
|
||||||
@@ -178,15 +182,19 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean
|
|||||||
|
|
||||||
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
|
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
|
||||||
|
|
||||||
compiler_moc_header_make_all: moc_mainwindow.cpp
|
compiler_moc_header_make_all: moc_mainwindow.cpp moc_udpsender.cpp
|
||||||
compiler_moc_header_clean:
|
compiler_moc_header_clean:
|
||||||
-$(DEL_FILE) moc_mainwindow.cpp
|
-$(DEL_FILE) moc_mainwindow.cpp moc_udpsender.cpp
|
||||||
moc_mainwindow.cpp: adpainter.h \
|
moc_mainwindow.cpp: adpainter.h \
|
||||||
basestruct.h \
|
basestruct.h \
|
||||||
aliens.h \
|
aliens.h \
|
||||||
|
udpsender.h \
|
||||||
mainwindow.h
|
mainwindow.h
|
||||||
/usr/bin/moc $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp
|
/usr/bin/moc $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp
|
||||||
|
|
||||||
|
moc_udpsender.cpp: udpsender.h
|
||||||
|
/usr/bin/moc $(DEFINES) $(INCPATH) udpsender.h -o moc_udpsender.cpp
|
||||||
|
|
||||||
compiler_rcc_make_all:
|
compiler_rcc_make_all:
|
||||||
compiler_rcc_clean:
|
compiler_rcc_clean:
|
||||||
compiler_image_collection_make_all: qmake_image_collection.cpp
|
compiler_image_collection_make_all: qmake_image_collection.cpp
|
||||||
@@ -213,13 +221,15 @@ compiler_clean: compiler_moc_header_clean compiler_uic_clean
|
|||||||
main.o: main.cpp mainwindow.h \
|
main.o: main.cpp mainwindow.h \
|
||||||
adpainter.h \
|
adpainter.h \
|
||||||
basestruct.h \
|
basestruct.h \
|
||||||
aliens.h
|
aliens.h \
|
||||||
|
udpsender.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
|
||||||
|
|
||||||
mainwindow.o: mainwindow.cpp mainwindow.h \
|
mainwindow.o: mainwindow.cpp mainwindow.h \
|
||||||
adpainter.h \
|
adpainter.h \
|
||||||
basestruct.h \
|
basestruct.h \
|
||||||
aliens.h \
|
aliens.h \
|
||||||
|
udpsender.h \
|
||||||
ui_mainwindow.h
|
ui_mainwindow.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp
|
||||||
|
|
||||||
@@ -231,6 +241,9 @@ aliens.o: aliens.cpp aliens.h \
|
|||||||
basestruct.h
|
basestruct.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o aliens.o aliens.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o aliens.o aliens.cpp
|
||||||
|
|
||||||
|
udpsender.o: udpsender.cpp udpsender.h
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o udpsender.o udpsender.cpp
|
||||||
|
|
||||||
towers.o: towers.cpp towers.h \
|
towers.o: towers.cpp towers.h \
|
||||||
basestruct.h
|
basestruct.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o towers.o towers.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o towers.o towers.cpp
|
||||||
@@ -238,6 +251,9 @@ towers.o: towers.cpp towers.h \
|
|||||||
moc_mainwindow.o: moc_mainwindow.cpp
|
moc_mainwindow.o: moc_mainwindow.cpp
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp
|
||||||
|
|
||||||
|
moc_udpsender.o: moc_udpsender.cpp
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_udpsender.o moc_udpsender.cpp
|
||||||
|
|
||||||
####### Install
|
####### Install
|
||||||
|
|
||||||
install: FORCE
|
install: FORCE
|
||||||
|
|||||||
@@ -60,8 +60,10 @@ void adpainter::drawgrid()
|
|||||||
void adpainter::drawAliens(deque<QPointF> path, FPVector * position)
|
void adpainter::drawAliens(deque<QPointF> path, FPVector * position)
|
||||||
{
|
{
|
||||||
float tmpdx,tmpdy,arctg,tmpdx1,tmpdy1;
|
float tmpdx,tmpdy,arctg,tmpdx1,tmpdy1;
|
||||||
|
//unsigned char dd[4];
|
||||||
|
//int gg;
|
||||||
arctg = 0;
|
arctg = 0;
|
||||||
QTransform rotated;
|
//QTransform rotated;
|
||||||
painter.begin(buff);
|
painter.begin(buff);
|
||||||
pen->setColor(QColor::fromRgb(qRgb(80,200,100)));
|
pen->setColor(QColor::fromRgb(qRgb(80,200,100)));
|
||||||
brush->setColor(QColor::fromRgb(qRgb(230,10,10)));
|
brush->setColor(QColor::fromRgb(qRgb(230,10,10)));
|
||||||
@@ -74,35 +76,50 @@ void adpainter::drawAliens(deque<QPointF> path, FPVector * position)
|
|||||||
}
|
}
|
||||||
tmpdx = position->pnt.x() - path.at(StepAlien).x()*cellsize;
|
tmpdx = position->pnt.x() - path.at(StepAlien).x()*cellsize;
|
||||||
tmpdy = position->pnt.y() - path.at(StepAlien).y()*cellsize;
|
tmpdy = position->pnt.y() - path.at(StepAlien).y()*cellsize;
|
||||||
tmpdx1 = position->pnt.x() - path.at(StepAlien+1).x()*cellsize;
|
if (StepAlien + 2 < path.size()) {
|
||||||
tmpdy1 = position->pnt.y() - path.at(StepAlien+1).y()*cellsize;
|
tmpdx1 = position->pnt.x() - path.at(StepAlien+2).x()*cellsize;
|
||||||
/*if (qAbs(tmpdy1) > 0.01 && qAbs(tmpdx1) > 0.01)*/ arctg = atan(tmpdx1/tmpdy1);
|
tmpdy1 = position->pnt.y() - path.at(StepAlien+2).y()*cellsize;
|
||||||
|
}
|
||||||
|
arctg = atanf(tmpdx1/tmpdy1);
|
||||||
|
//memcpy(&gg,&arctg,4);
|
||||||
|
if (tmpdy1 != 0) position->angle = 180*(-arctg)/3.1415;
|
||||||
if (AlienPix.size() > 0) {
|
if (AlienPix.size() > 0) {
|
||||||
//painter.rotate((arctg/3.1415)*180);
|
//painter.rotate((arctg/3.1415)*180);
|
||||||
rotated.rotateRadians(arctg/* + 3.1415/2*/);
|
//rotated.rotateRadians(arctg/* + 3.1415/2*/);
|
||||||
qDebug() << "angle:" << arctg;
|
//qDebug() << "angle:" << arctg;
|
||||||
painter.save();
|
//rotated.reset();
|
||||||
painter.translate(position->pnt.x()+cellsize,position->pnt.y()+cellsize);
|
|
||||||
//if (arctg == 0) painter.rotate(90);
|
|
||||||
position->angle = 180*(-arctg)/3.1415;
|
|
||||||
painter.rotate(position->angle);
|
|
||||||
//position->pnt.setX(path.at(0).x());
|
|
||||||
//position->pnt.setY(path.at(0).y());
|
|
||||||
painter.drawPixmap(0, 0, cellsize*2, cellsize*2, AlienPix.at(AnimAlien));
|
|
||||||
AnimAlien++;
|
|
||||||
painter.restore();
|
|
||||||
rotated.reset();
|
|
||||||
if (qAbs(tmpdx) < 1 && qAbs(tmpdy) < 1) StepAlien++;
|
if (qAbs(tmpdx) < 1 && qAbs(tmpdy) < 1) StepAlien++;
|
||||||
else {
|
else {
|
||||||
if (qAbs(tmpdx) <= qAbs(tmpdy)) {
|
if (qAbs(tmpdx) <= qAbs(tmpdy)) {
|
||||||
if (tmpdy < 0) position->pnt.ry()++;
|
if (tmpdy < 0) {
|
||||||
else position->pnt.ry()--;
|
position->pnt.ry()++;
|
||||||
|
//position->angle = - position->angle;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
position->pnt.ry()--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (qAbs(tmpdx) >= qAbs(tmpdy)) {
|
if (qAbs(tmpdx) >= qAbs(tmpdy)) {
|
||||||
if (tmpdx < 0) position->pnt.rx()++;
|
if (tmpdx < 0) {
|
||||||
|
position->pnt.rx()++;
|
||||||
|
//position->angle = - position->angle;
|
||||||
|
}
|
||||||
else position->pnt.rx()--;
|
else position->pnt.rx()--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//painter.save();
|
||||||
|
painter.translate(position->pnt.x()-cellsize,position->pnt.y()-cellsize);
|
||||||
|
//if (arctg == 0) painter.rotate(90);
|
||||||
|
//memcpy(dd,&gg,4);
|
||||||
|
//dd[0]=0xFF;
|
||||||
|
qDebug() << "angle:" << position->angle;
|
||||||
|
//qDebug() << dd[0] << dd[1] << dd[2] << dd[3];
|
||||||
|
painter.rotate(position->angle);
|
||||||
|
//position->pnt.setX(path.at(0).x());
|
||||||
|
//position->pnt.setY(path.at(0).y());
|
||||||
|
painter.drawPixmap(cellsize/2, cellsize/2, cellsize*2, cellsize*2, AlienPix.at(AnimAlien));
|
||||||
|
AnimAlien++;
|
||||||
|
//painter.restore();
|
||||||
if (AnimAlien >= AlienPix.size()) AnimAlien = 0;
|
if (AnimAlien >= AlienPix.size()) AnimAlien = 0;
|
||||||
if (StepAlien >= path.size()) StepAlien = 0;
|
if (StepAlien >= path.size()) StepAlien = 0;
|
||||||
//qDebug() << StepAlien;
|
//qDebug() << StepAlien;
|
||||||
|
|||||||
BIN
adpainter.o
BIN
adpainter.o
Binary file not shown.
@@ -80,6 +80,13 @@ bool Aliens::CreatePath(Alien * al)
|
|||||||
al->Position.pnt.setX(al->path.at(0).x()*cellsize);
|
al->Position.pnt.setX(al->path.at(0).x()*cellsize);
|
||||||
al->Position.pnt.setY(al->path.at(0).y()*cellsize);
|
al->Position.pnt.setY(al->path.at(0).y()*cellsize);
|
||||||
}
|
}
|
||||||
|
int i = 0;
|
||||||
|
tmpPnt.clear();
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
tp = al->path[0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
: QMainWindow(parent), ui(new Ui::MainWindow)
|
: QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
sndr = new UdpSender("127.0.0.1",10101);
|
||||||
|
sndr->connectSend("hellow");
|
||||||
cellsize = 16;
|
cellsize = 16;
|
||||||
destx = this->width() / cellsize / 2;
|
destx = this->width() / cellsize / 2;
|
||||||
desty = this->height() / cellsize;
|
desty = this->height() / cellsize;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "adpainter.h"
|
#include "adpainter.h"
|
||||||
#include "aliens.h"
|
#include "aliens.h"
|
||||||
|
#include "udpsender.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@@ -30,6 +31,7 @@ private:
|
|||||||
void mousePressEvent ( QMouseEvent * event );
|
void mousePressEvent ( QMouseEvent * event );
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
Aliens * aliens;
|
Aliens * aliens;
|
||||||
|
UdpSender * sndr;
|
||||||
adpainter * adp;
|
adpainter * adp;
|
||||||
bool mousebt;
|
bool mousebt;
|
||||||
int cellsize, destx, desty;
|
int cellsize, destx, desty;
|
||||||
|
|||||||
BIN
mainwindow.o
BIN
mainwindow.o
Binary file not shown.
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
** Meta object code from reading C++ file 'mainwindow.h'
|
** Meta object code from reading C++ file 'mainwindow.h'
|
||||||
**
|
**
|
||||||
** Created: Sat Aug 29 11:41:18 2009
|
** Created: Mon Aug 31 09:51:05 2009
|
||||||
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
|
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
|
||||||
**
|
**
|
||||||
** WARNING! All changes made in this file will be lost!
|
** WARNING! All changes made in this file will be lost!
|
||||||
|
|||||||
BIN
moc_mainwindow.o
BIN
moc_mainwindow.o
Binary file not shown.
73
moc_udpsender.cpp
Normal file
73
moc_udpsender.cpp
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Meta object code from reading C++ file 'udpsender.h'
|
||||||
|
**
|
||||||
|
** Created: Mon Aug 31 09:51:08 2009
|
||||||
|
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
|
||||||
|
**
|
||||||
|
** WARNING! All changes made in this file will be lost!
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "udpsender.h"
|
||||||
|
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||||
|
#error "The header file 'udpsender.h' doesn't include <QObject>."
|
||||||
|
#elif Q_MOC_OUTPUT_REVISION != 61
|
||||||
|
#error "This file was generated using the moc from 4.5.2. It"
|
||||||
|
#error "cannot be used with the include files from this version of Qt."
|
||||||
|
#error "(The moc has changed too much.)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QT_BEGIN_MOC_NAMESPACE
|
||||||
|
static const uint qt_meta_data_UdpSender[] = {
|
||||||
|
|
||||||
|
// content:
|
||||||
|
2, // revision
|
||||||
|
0, // classname
|
||||||
|
0, 0, // classinfo
|
||||||
|
1, 12, // methods
|
||||||
|
0, 0, // properties
|
||||||
|
0, 0, // enums/sets
|
||||||
|
0, 0, // constructors
|
||||||
|
|
||||||
|
// slots: signature, parameters, type, tag, flags
|
||||||
|
11, 10, 10, 10, 0x0a,
|
||||||
|
|
||||||
|
0 // eod
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char qt_meta_stringdata_UdpSender[] = {
|
||||||
|
"UdpSender\0\0slotRead()\0"
|
||||||
|
};
|
||||||
|
|
||||||
|
const QMetaObject UdpSender::staticMetaObject = {
|
||||||
|
{ &QObject::staticMetaObject, qt_meta_stringdata_UdpSender,
|
||||||
|
qt_meta_data_UdpSender, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
const QMetaObject *UdpSender::metaObject() const
|
||||||
|
{
|
||||||
|
return &staticMetaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *UdpSender::qt_metacast(const char *_clname)
|
||||||
|
{
|
||||||
|
if (!_clname) return 0;
|
||||||
|
if (!strcmp(_clname, qt_meta_stringdata_UdpSender))
|
||||||
|
return static_cast<void*>(const_cast< UdpSender*>(this));
|
||||||
|
return QObject::qt_metacast(_clname);
|
||||||
|
}
|
||||||
|
|
||||||
|
int UdpSender::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||||
|
{
|
||||||
|
_id = QObject::qt_metacall(_c, _id, _a);
|
||||||
|
if (_id < 0)
|
||||||
|
return _id;
|
||||||
|
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||||
|
switch (_id) {
|
||||||
|
case 0: slotRead(); break;
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
_id -= 1;
|
||||||
|
}
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
QT_END_MOC_NAMESPACE
|
||||||
BIN
moc_udpsender.o
Normal file
BIN
moc_udpsender.o
Normal file
Binary file not shown.
45
udpsender.cpp
Normal file
45
udpsender.cpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include "udpsender.h"
|
||||||
|
|
||||||
|
|
||||||
|
UdpSender::UdpSender(QString IP, quint16 Port)
|
||||||
|
{
|
||||||
|
sock = new QUdpSocket();
|
||||||
|
qDebug() << sock->state();
|
||||||
|
//cout << sock->socketDescriptor() << endl;
|
||||||
|
//qDebug() << sock->socketDescriptor();
|
||||||
|
addr = QHostAddress(IP);
|
||||||
|
port = Port;
|
||||||
|
connect(sock, SIGNAL(readyRead()),this, SLOT(slotRead()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UdpSender::~UdpSender()
|
||||||
|
{
|
||||||
|
sock->close();
|
||||||
|
delete sock;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UdpSender::slotRead()
|
||||||
|
{
|
||||||
|
QString s;
|
||||||
|
QByteArray * recdata = new QByteArray();
|
||||||
|
*recdata = sock->readAll();
|
||||||
|
s = *recdata;
|
||||||
|
cout << "Received data: ";
|
||||||
|
for (int i = 0; i < s.length(); i++) cout << s[i].toAscii();
|
||||||
|
cout << endl;
|
||||||
|
qDebug() << sock->write(recstr.toUtf8());
|
||||||
|
qDebug() << sock->socketDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UdpSender::connectSend(QString s)
|
||||||
|
{
|
||||||
|
sz = s.length();
|
||||||
|
sock->connectToHost(addr,port);
|
||||||
|
qDebug() << sock->error();
|
||||||
|
qDebug() << sock->state();
|
||||||
|
qDebug() << sock->socketDescriptor();
|
||||||
|
if (sock->write(s.toUtf8())>0) qDebug() << "writen!";
|
||||||
|
}
|
||||||
24
udpsender.h
Normal file
24
udpsender.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <QUdpSocket>
|
||||||
|
#include <QObject>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
|
class UdpSender : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QString recstr;
|
||||||
|
UdpSender(QString IP, quint16 Port);
|
||||||
|
~UdpSender();
|
||||||
|
void connectSend(QString s);
|
||||||
|
public slots:
|
||||||
|
void slotRead();
|
||||||
|
private:
|
||||||
|
QUdpSocket * sock;
|
||||||
|
QHostAddress addr;
|
||||||
|
quint16 port;
|
||||||
|
quint32 sz;
|
||||||
|
QByteArray * senddata;
|
||||||
|
};
|
||||||
BIN
udpsender.o
Normal file
BIN
udpsender.o
Normal file
Binary file not shown.
@@ -1,7 +1,7 @@
|
|||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
** Form generated from reading ui file 'mainwindow.ui'
|
** Form generated from reading ui file 'mainwindow.ui'
|
||||||
**
|
**
|
||||||
** Created: Sat Aug 29 00:10:28 2009
|
** Created: Mon Aug 31 09:50:43 2009
|
||||||
** by: Qt User Interface Compiler version 4.5.2
|
** by: Qt User Interface Compiler version 4.5.2
|
||||||
**
|
**
|
||||||
** WARNING! All changes made in this file will be lost when recompiling ui file!
|
** WARNING! All changes made in this file will be lost when recompiling ui file!
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ SOURCES += main.cpp \
|
|||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
adpainter.cpp \
|
adpainter.cpp \
|
||||||
aliens.cpp \
|
aliens.cpp \
|
||||||
|
udpsender.cpp \
|
||||||
towers.cpp
|
towers.cpp
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
adpainter.h \
|
adpainter.h \
|
||||||
aliens.h \
|
aliens.h \
|
||||||
basestruct.h \
|
basestruct.h \
|
||||||
|
udpsender.h \
|
||||||
towers.h
|
towers.h
|
||||||
FORMS += mainwindow.ui
|
FORMS += mainwindow.ui
|
||||||
|
|||||||
Reference in New Issue
Block a user