... can help me
my code:
{
Q_OBJECT
public:
CProjectManager *m_pPrj;
HSM
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~HSM();
private:
Ui::HSMClass ui;
Server server;
private slots:
void on_pushButton_clicked();
};
class HSM : public QDialog
{
Q_OBJECT
public:
CProjectManager *m_pPrj;
HSM(QWidget *parent = 0, Qt::WFlags flags = 0);
~HSM();
private:
Ui::HSMClass ui;
Server server;
private slots:
void on_pushButton_clicked();
void SetLine(QString cMsg);
};
To copy to clipboard, switch view to plain text mode
HSM
::HSM(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
this,
SLOT(SetLine
(QString cMsg
)));
// ??????? }
HSM::~HSM()
{
//m_pPrj->FreeInst();
}
void HSM::on_pushButton_clicked()
{
//some code
}
{
ui.listWidget->addItem(cMsg);
}
HSM::HSM(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
ui.setupUi(this);
QObject::connect(this, SIGNAL(SendMSG(QString)),
this, SLOT(SetLine(QString cMsg)));// ???????
}
HSM::~HSM()
{
//m_pPrj->FreeInst();
}
void HSM::on_pushButton_clicked()
{
//some code
}
void HSM::SetLine(QString cMsg)
{
ui.listWidget->addItem(cMsg);
}
To copy to clipboard, switch view to plain text mode
class FortuneThread
: public QThread{
Q_OBJECT
public:
FortuneThread
(int socketDescriptor,
QObject *parent
);
~FortuneThread();
void run();
signals:
private:
int socketDescriptor;
};
class FortuneThread : public QThread
{
Q_OBJECT
public:
FortuneThread(int socketDescriptor,QObject *parent);
~FortuneThread();
void run();
signals:
void error(QTcpSocket::SocketError socketError);
private:
int socketDescriptor;
};
To copy to clipboard, switch view to plain text mode
FortuneThread
::FortuneThread(int socketDescriptor,
QObject *parent
) : QThread(parent
), socketDescriptor
(socketDescriptor
) {
}
FortuneThread::~FortuneThread()
{
}
void FortuneThread::run()
{
Connection connection;
if(!connection.setSocketDescriptor(socketDescriptor))
{
emit error(connection.error());
return;
}
connect(&connection, SIGNAL(disconnected()), this, SLOT(quit()));
exec();
}
FortuneThread::FortuneThread(int socketDescriptor,QObject *parent)
: QThread(parent), socketDescriptor(socketDescriptor)
{
}
FortuneThread::~FortuneThread()
{
}
void FortuneThread::run()
{
Connection connection;
if(!connection.setSocketDescriptor(socketDescriptor))
{
emit error(connection.error());
return;
}
connect(&connection, SIGNAL(disconnected()), this, SLOT(quit()));
exec();
}
To copy to clipboard, switch view to plain text mode
{
Q_OBJECT
public:
private slots:
void processReadyRead();
signals:
};
class Connection : public QTcpSocket
{
Q_OBJECT
public:
Connection(QObject *parent = 0);
private slots:
void processReadyRead();
signals:
void SendMSG(QString cMsg);
};
To copy to clipboard, switch view to plain text mode
Connection
::Connection(QObject *parent
){
QObject::connect(this,
SIGNAL(readyRead
()),
this,
SLOT(processReadyRead
()));
}
void Connection::processReadyRead()
{
//some code
//
//
emit SendMSG("new_line");
}
Connection::Connection(QObject *parent)
: QTcpSocket(parent)
{
QObject::connect(this, SIGNAL(readyRead()), this, SLOT(processReadyRead()));
}
void Connection::processReadyRead()
{
//some code
//
//
emit SendMSG("new_line");
}
To copy to clipboard, switch view to plain text mode
{
Q_OBJECT
public:
signals:
void newConnection(Connection *connection);
protected:
void incomingConnection(int socketDescriptor);
};
class Server : public QTcpServer
{
Q_OBJECT
public:
Server(QObject *parent = 0);
signals:
void newConnection(Connection *connection);
protected:
void incomingConnection(int socketDescriptor);
};
To copy to clipboard, switch view to plain text mode
{
return;
}
}
void Server::incomingConnection(int socketDescriptor)
{
FortuneThread *thread = new FortuneThread(socketDescriptor,this);
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
Server::Server(QObject *parent):QTcpServer(parent)
{
if (!listen(QHostAddress::Any,1718)) {
return;
}
}
void Server::incomingConnection(int socketDescriptor)
{
FortuneThread *thread = new FortuneThread(socketDescriptor,this);
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
To copy to clipboard, switch view to plain text mode
But at connection of the client record all the same does not appear Where I was mistaken?
Bookmarks