标签:
{ QApplication* app; app->exit(0); }
{ QApplication* app; app->quit(); }
QPushButton *quitButton = new QPushButton( "Quit" ); connect( quitButton, SIGNAL(clicked()), qApp, SLOT(quit()) );
if (!(QMessageBox::information(this,tr("CT Control View"),tr("Do you really want to log out CT Control View?"),tr("Yes"),tr("No")))) { this->close(); }
void mainWindow::closeEvent( QCloseEvent * event ) { switch( QMessageBox::information( this, tr("CT Control View"), tr("Do you really want to log out CT Control View?"), tr("Yes"), tr("No"), 0, 1 ) ) { case 0: event->accept(); break; case 1: default: event->ignore(); break; } }
int main( int argc, char ** argv ) { QApplication a( argc, argv ); ABMainWindow *mw = new ABMainWindow(); mw->setCaption( "Qt Example - Addressbook" ); a.setMainWidget( mw ); mw->show(); a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); int result = a.exec(); delete mw; return result; }
connect(ui.RECVpushButton,SIGNAL(clicked()),this,SLOT(test()));
connect(&tcpThread,SIGNAL(SignalRecv()),this,SLOT(receNetConnect()));
void MainWindow::receNetConnect()
{
tcpipLink.TCPIPRecvData();
//tcpipLink.TCPIPCheck();
data[0]=tcpipLink.recvbuf[0];
data[1]=tcpipLink.recvbuf[1];
data[2]=tcpipLink.recvbuf[2];
data[3]=tcpipLink.recvbuf[3];
data[4]=tcpipLink.recvbuf[4];
data[5]=tcpipLink.recvbuf[5];
data[6]=tcpipLink.recvbuf[6];
data[7]=tcpipLink.recvbuf[7];
data[8]=tcpipLink.recvbuf[8];
data[9]=tcpipLink.recvbuf[9];
data[10]=tcpipLink.recvbuf[10];
//第二种赋值 利用数组
//data[0]=tcpipLink.dddd[0];
//data[1]=tcpipLink.dddd[1];
//data[2]=tcpipLink.dddd[2];
//data[3]=tcpipLink.dddd[3];
//data[4]=tcpipLink.dddd[4];
//data[5]=tcpipLink.dddd[5];
s1 = QString::number(data[0],‘f‘,6);
s2 = QString::number(data[1],‘f‘,6);
s3 = QString::number(data[2],‘f‘,6);
s4 = QString::number(data[3],‘f‘,6);
s5 = QString::number(data[4],‘f‘,6);
s6 = QString::number(data[5],‘f‘,6);
s7 = QString::number(data[6],‘f‘,6);
s8 = QString::number(data[7],‘f‘,6);
s9 = QString::number(data[8],‘f‘,6);
s10 = QString::number(data[9],‘f‘,6);
s11 = QString::number(data[10],‘f‘,6);
ui.lineEdit->setText(s1);
ui.lineEdit_2->setText(s2);
ui.lineEdit_3->setText(s3);
ui.lineEdit_4->setText(s4);
ui.lineEdit_5->setText(s5);
ui.lineEdit_6->setText(s6);
ui.lineEdit_joint1->setText(s7);
ui.lineEdit_joint2->setText(s8);
ui.lineEdit_joint3->setText(s9);
ui.lineEdit_joint4->setText(s10);
ui.lineEdit_joint5->setText(s11);
}
void MainWindow::test()
{
tcpThread.start();
}
void MainWindow::Stop()
{
printf("it‘s stop!\n");
tcpThread.terminate();
}
ThreadTCP
void ThreadTCP::run()
{
//emit SignalLink();
//emit SignalRecv();
while(1)
{
if(m_stopFlag==false)
{
break;
}
printf("OK!\n");
Sleep(400);
emit SignalRecv();
}
}
即可将该线程终止,并能继续接收数据!!!!!!!
Qt学习经验之quit()、exit()、close()《转载》
标签:
原文地址:http://www.cnblogs.com/splovecyk/p/4463909.html