NetworkInformation::NetworkInformation( QWidget *parent, Qt::WindowFlags f ) : QDialog( parent, f ) { setWindowTitle(tr("Network Information")); LabelLocalHostName = new QLabel(); LabelLocalHostName->setText(tr("localhostname:")); LineEditLocalHostName = new QLineEdit(); LabelAddress = new QLabel(); LabelAddress->setText(tr("address:")); LineEditAddress = new QLineEdit(); PushButtonDetail = new QPushButton( this); PushButtonDetail->setText( tr( "Detail" ) ); QHBoxLayout *hbLayout1 = new QHBoxLayout (); hbLayout1->addWidget(LabelLocalHostName); hbLayout1->addWidget(LineEditLocalHostName); QHBoxLayout *hbLayout2 = new QHBoxLayout (); hbLayout2->addWidget(LabelAddress); hbLayout2->addWidget(LineEditAddress); QVBoxLayout *vbLayout = new QVBoxLayout( this ); vbLayout->addLayout( hbLayout1 ); vbLayout->addLayout( hbLayout2 ); vbLayout->addWidget( PushButtonDetail ); connect(PushButtonDetail,SIGNAL(clicked()),this,SLOT(slotDetail())); getHostInformation(); }
void MainWindow::on_pushButtonStart_clicked() { if(tcpSever == NULL) { tcpSever = new MyTcpSever(this); tcpSever->listen(QHostAddress::Any, 6000); connect(tcpSever, SIGNAL(GetImage(QImage,int)), this, SLOT(Disp(QImage,int))); connect(this, SIGNAL(SendData(int, QByteArray)), tcpSever, SIGNAL(SendData(int, QByteArray))); connect(tcpSever, SIGNAL(GetParameterData(QVector<int>)), this, SLOT(onRecvParamterData(QVector<int>))); getHostInformation(); }
MainWindow::MainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); companyWebAddress ="explorer http://www.oschina.net/p/qtsharp"; pingNet ="Ping www.baidu.com"; //实现ping值的实时测量 getPing(); QTimer *pingTimer=new QTimer(this);//此段作用是用一个定时器,每隔5s,查看一次当前ping值。 connect(pingTimer,SIGNAL(timeout()),this,SLOT(pingTimeOut())); pingTimer->start(5000); bool ok=false; //定义声明一个服务器实体。 getHostInformation(); port=this->ui->editPort->text().toInt(&ok,10); tcpserver=new TcpServer(this,port); //将server中的有用变量都复制到本函数中。 robotHash=tcpserver->getRobotIDHash(); robotNumberOnLine=tcpserver->getRobotNumber(); showClientMessage(); connect(tcpserver,SIGNAL(receiveDataSource(ProtocolFromClient2Server)),this,SLOT(receiveData(ProtocolFromClient2Server)));//接收数据槽函数。 connect(this,SIGNAL(sendDataSource(QString,int)),this,SLOT(sendData(QString,int)));//发送数据槽函数。 }