Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

c++ - Why doesn't QTextBrowser::clear() work immediately when i call it?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...