Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Server : public QObject { Q _ OBJECT public: explicit Server ( QObject * parent = 0 ) ; / / must be explicitly

class Server : public QObject
{
Q_OBJECT
public:
explicit Server(QObject *parent =0); //must be explicitly called to create an object of the Server class. The constructor takes a single parameter of type QObject*, which is a pointer to an object of the QObject class (or one of its subclasses). The parameter is given a default value of nullptr (or 0 in older code), which means that if the constructor is called without providing a value for parent, it will default to a null pointer.
signals:
void dataReceived(QByteArray);//The dataReceived signal you provided declares a signal named dataReceived that takes a single parameter of type QByteArray. This signal indicates that an object of this class emits the dataReceived signal when it receives data, and it passes a QByteArray containing the received data as an argument.
private slots://can be connected to signals
void newConnection();
void disconnected();
void readyRead();
private:
QTopServer *server;
QHash buffers;
QHash sizes;
};
Server :: Server(QObject*parent) : QObject(parent)
{
server = new QTopServer(this);
connect(server,SIGNAL(newConnection()), SLOT(newConnection()));
server->listen(QHostAddress::Any,7755);
}
void Server :: newConnection()
{
while(server->hasPendingConnections())
{
QTopSocket *socket = server->nextPendingConnection();
connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(socket, SIGNAL(desconnected()), this, SLOT(disconnected()));
QByteArray *buffer = new QByteArray();
qint32*s = new qint32(0);
buffers.insert(socket, buffer);
sizes.insert(socket, s);
}
}
void Server :: disconnected()
{
QTopSocket *socket = static.cast(sender());
QByteArray *buffer = buffers.value(socket);
buffers.remove(socket);
qint32*s = sizes.value(socket);
sizes.remove(socket);
socket->deleteLater();
delete buffer;
delete s;
}
void Server :: readyRead()
{
QTopSocket *socket = static.cast(sender());
QByteArray *buffer = buffer.value(socket);
qint32*s = sizes.value(socket);
qint32 size =*s;
while(socket->bytesAvailable()>0)
{
buffer->append(socket->readAll())
}
}
Can you please draw a class diagram which include the following classes: QObject , QTopSocket, Server, QByteArray, QTopServer. There must be attributes or methods in classes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

=+b. What proportion of these patients had at most two impairments?

Answered: 1 week ago

Question

8. Set goals that relate to practice as well as competition.

Answered: 1 week ago

Question

Compare the advantages and disadvantages of external recruitment.

Answered: 1 week ago

Question

Describe the typical steps in the selection process.

Answered: 1 week ago