www.gusucode.com > qt实现的多线程服务器和客户端源码程序 > qt实现的多线程服务器和客户端源码程序/qtserver/server/mainwindow.cpp
#include "mainwindow.h" #include <QtGui> #include <QtNetwork> #include <stdlib.h> #include "shopserver.h" namespace HztqLee { MainWindow::MainWindow(QWidget *parent) : QDialog(parent) { statusLabel = new QLabel; quitButton = new QPushButton(tr("Quit")); quitButton->setAutoDefault(false); if (!server.listen(QHostAddress::Any, 2099)) { QMessageBox::critical(this, tr("Threaded Fortune Server"), tr("Unable to start the server: %1.") .arg(server.errorString())); close(); return; } statusLabel->setText(QString("The server is running on port %1.\n" "Run中文 the Fortune Client example now.") .arg(server.serverPort())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(quitButton); buttonLayout->addStretch(1); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); mainLayout->addLayout(buttonLayout); setLayout(mainLayout); setWindowTitle("Threaded 中文 Server"); } }