源码
关键代码
void Widget::PostRequest()
{
if(ui->lineEdit->text().isEmpty())
{
qDebug()<<"lineEdit is empty";
//生成随机数
auto randNum = QRandomGenerator::global()->generate();
auto randUrl = url.url() + QString::number(randNum) + ".png";
// randUrl.append("?apikey=").append(apiKey);
request.setUrl(randUrl);
manager->get(request);
}
else
{
qDebug()<<"post requst";
QString lineText = ui->lineEdit->text();
auto tUrl = url.url() + lineText + ".png";
// tUrl.append("?apikey=").append(apiKey);
// qDebug()<<"url"<<tUrl;
request.setUrl(tUrl);
manager->get(request);
}
num = 0;
ui->progressBar->reset();
ui->progressBar->setFormat(QString("正在生成中%p%"));
connect(&timer,&QTimer::timeout,[&](){
qDebug()<<"timeout"<<num;
if(num<100)
{
ui->progressBar->setValue(num++);
}
});
timer.start(500);
}
效果
![](https://i-blog.csdnimg.cn/direct/f6ab1be2ab044c868a76ab0b46004bf9.png)
创作不易,小小的支持一下吧!
![](https://img-blog.csdnimg.cn/direct/2d50062d779a47afb478b75948ec28e5.png)
![](https://img-blog.csdnimg.cn/direct/d4a3f7989b534e9b8b67a6fa085b1129.jpeg)