I want achieve a function : when I clickt the "start" button,the textBrowser will be cleaned up immediately and then the textBrowser show something for user.But I use QtextBrowser::clean()
,it didn't work immediately.
//constructor
connect(StartBtn,SIGNAL(clicked()),this,SLOT(interfaceStart()));
bool MainWindow::interfaceStart()
{
ui->textBrowser->clear();// this line does not seem to work immediately before `while(fgets...)` loop is finished;
if(interfaceLine->text()!=QString("") && interfaceSpinBox->text()!="0"){
ui->textBrowser->insertPlainText(QString("Starting capture interface %1
").arg(interfaceLine->text()));//this line also doesn't work
std::string cc = std::string("tshark -i ")
+std::string((interfaceLine->text()).toLocal8Bit().data())
+std::string(" -a duration:")
+std::string(interfaceSpinBox->text().toLocal8Bit().data());
char buf[1024];
char const *command=cc.c_str();
std::cout<<command;
std::cout.flush(); // when i see this line work, console will output command.But textBroser is't cleaned up
FILE *ptr;
if((ptr=popen(command, "r"))!=NULL)
{
while(fgets(buf, 1024, ptr)!=NULL)
{
ui->textBrowser->insertPlainText(buf);
}
pclose(ptr);
ptr = NULL;
}
return true;
}
QMessageBox::warning(this,QString("Error"),QString("Interface %1 doesn't exist or time is 0!").arg(interfaceLine->text()));
return false;
}
I saw console print command
first,but testBrowser isn't cleaned up.When popen() isfinished,testBrowser will be cleaned.Why?
How to make clean()
work right now?Can i flush the textBrowser?
question from:
https://stackoverflow.com/questions/65950818/why-doesnt-qtextbrowserclear-work-immediately-when-i-call-it 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…