QTextEdit信息实时更新显示

void MainWindow::on_Button1_clicked(){
    for(int i = 0; i < 10; i++){
        //滚动条保持底部
        QScrollBar *scrollbar = ui->console->verticalScrollBar();
        if(scrollbar){
            scrollbar->setSliderPosition(scrollbar->maximum());
        }
        //输入数据
        QString out = "Hello World\n";
        ui->console->insertPlainText(out);
        Sleep(50);
        //重要的是下边这句
        QApplication::processEvents();
    }
}

你可能感兴趣的:(c++)