当前位置:我的异常网» QT开发 » Qt tcp 多线程下QTCPsocket不能发送数据~解决办法
Qt tcp 多线程下QTCPsocket不能发送数据~解决办法(3)
www.myexceptions.net 网友分享于:2015-08-26 浏览:1294次
autosendstat = false;
memset(m_buffer,0,sizeof(m_buffer));
//connect(,SIGNAL(),this,SLOT());
connect(p_socketet,SIGNAL(readyRead()),this,SLOT(SockRecvData())); //有数据来
connect(p_socketet,SIGNAL(disconnect()),this,SLOT(connectError()));
connect(p_socketet,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(socketerror()));
ui-> pushButton_send-> setEnabled(false);
SocketTCPstart();
}
MainWindow::~MainWindow()
{
delete ui;
delete p_socketet;
}
void MainWindow::SocketTCPstart()
{
p_longfile = new QSettings( "ClientConfig.ini ",QSettings::IniFormat,0);
QString temp_STR = p_longfile-> value( "CLIENT_CONFIG/SERVERIP ").toString();
int temp_I = p_longfile-> value( "CLIENT_CONFIG/SERVERPORT ").toUInt();
if(temp_STR.isEmpty()||(temp_I == 0))
{
ui-> label_dissata-> setText( "错误:client启动失败!可能是配置文件出错! ");
return;
}
else
ui-> pushButton_send-> setEnabled(true);
p_socketet-> connectToHost(temp_STR,temp_I,QIODevice::WriteOnly);
delete p_longfile;
}
bool MainWindow::GenerateCW(char *buffer)
{
......
}
void MainWindow::SockSendData(char *buffer)
{
// GenerateCW(buffer);
p_socketet-> write(buffer,8);
}
void MainWindow::on_pushButton_send_clicked()
{
if( GenerateCW(m_buffer))
{
if(mthread.b_threadsata == true)
{
ui-> pushButton_send-> setText( "发送 ");
mthread.b_threadsata = false;
mthread.exit();
ui-> lineEdit-> clear();
}
if(ui-> lineEdit-> text().isEmpty()==false)
{
mthread.b_threadsata = false;
mthread.p_sock = p_socketet;
mthread.sendnumber =ui-> lineEdit-> text().toUInt();
mthread.p_senddata =m_buffer;
mthread.start();
// mthread.wait();
// ui-> pushButton_send-> setText( "停止 ");
}
else if(ui-> lineEdit-> text().isEmpty())
{
SockSendData(m_buffer);
}
}
}
void MainWindow::on_action_socket_close_triggered()
{
.....
}
void MainWindow::on_action_socket_open_triggered()
文章评论