多线程还是有问题,时不时闪退

This commit is contained in:
2022-01-05 14:30:45 +08:00
parent b54bbd39aa
commit ca5154d740
4 changed files with 21 additions and 10 deletions
+13 -6
View File
@@ -29,7 +29,8 @@ quint32 ipv4str_to_int(const QString& ipstr)
void trytry::run()
{
qDebug() << ipstr<<":"<< ipint;
*now_thread_num++;
*now_thread_num+=1;
QTcpSocket m_socket;
m_socket.connectToHost(ipstr, ipint, QTcpSocket::ReadWrite);
if (m_socket.waitForConnected(timeout))
@@ -39,10 +40,14 @@ void trytry::run()
}
m_socket.disconnectFromHost();
m_socket.disconnect();
*now_thread_num--;
*now_thread_num-=1;
*nt_bar++;
the_bar->setValue(((*nt_bar)/(*t_bar))*100);
*nt_bar+=1;
//((*nt_bar)/(*t_bar))*100
//the_bar->setValue(((0.0+*nt_bar)/(*t_bar))*100);
//qDebug()<<((0.0+*nt_bar)/(0.0+*t_bar))*100<<"%";
//the_bar->setValue(10);
qDebug()<<*nt_bar<<"/"<<*t_bar;
}
dispatch::dispatch()
@@ -82,6 +87,7 @@ void dispatch::run()
{
//qDebug()<< ui->IP_list->toPlainText();
//the_bar->setValue(20);
QTcpSocket* m_socket = new QTcpSocket;
@@ -128,7 +134,8 @@ void dispatch::run()
}
t_bar=ips_num*ports_num;
//qDebug()<<
nt_bar=0;
//qDebug()<<*t_bar;
//*****************************
for (int i = 0; i < str_ip_list.size(); ++i)
{
@@ -192,7 +199,7 @@ void dispatch::run()
}
//sleep(1);//稍微等一下其他线程完成
sleep(1);//稍微等一下其他线程完成
emit dispatch_finish();
}
+1 -1
View File
@@ -40,7 +40,7 @@ public:
quint16 set_thread_num;
quint16 now_thread_num;
quint16 timeout;
quint64 t_bar;
quint64 t_bar=0;
quint64 nt_bar=0;
QThread* main_thread;
+4 -1
View File
@@ -22,14 +22,17 @@ Widget::Widget(QWidget *parent)
//qDebug("hello world");
//ui->type_bar->setValue(10);
main_thread = new QThread(this);
main_thread->start();
connect(ui->stard_scan, &QPushButton::pressed, [=]()
{
dispatch* dispatch_thread;
dispatch_thread = new dispatch;
dispatch_thread->ip_list = ui->IP_list;
dispatch_thread->port_list = ui->port_list;
dispatch_thread->output_list = ui->outputlist;
+2 -1
View File
@@ -26,7 +26,8 @@ public:
QThread* main_thread;
quint64 *t_bar;
quint64 *nt_bar;
private:
Ui::Widget* ui;