程序
服务器
dialog类(界面编写)
.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include "timeserver.h"
#include <QMessageBox>
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
private:
QLabel *label1;
QLabel *label2;
QPushButton *quitBtn;
public slots:
void slotShow();
private:
TimeServer *timeServer;
int count;
};
#endif
.cpp
#include "dialog.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle("多线程时间服务器");
label1=new QLabel("服务器端口");
label2=new QLabel;
quitBtn=new QPushButton("退出");
QHBoxLayout *BtnLayout =new QHBoxLayout;
BtnLayout->addStretch(1);
BtnLayout->addWidget(quitBtn);
BtnLayout->addStretch(1);
QVBoxLayout *mainLayout=new QVBoxLayout(this);
mainLayout->addWidget(label1);
mainLayout->addWidget(label2);
mainLayout->addLayout(BtnLayout);
connect(quitBtn,SIGNAL(clicked()),this,SLOT(close()));
count=0;
timeServer = new TimeServer(this);
if(!timeServer->listen())
{
QMessageBox::critical(this,tr("多线程时间服务器"),
tr("无法启动服务器:%1.").arg(timeServer->errorString()));
close();
return;
}
label1->setText(tr("服务器端口:%1.").arg(timeServer->serverPort()));