QT如何显示,请等待对话框,而插座正在等待响应

Qt how to display please wait dialog whilst socket is waiting for response?

本文关键字:对话框 插座 响应 在等待 等待 何显示 显示 QT      更新时间:2023-10-16

我的功能发出了HTTP请求,服务器可能需要一些时间才能响应。在等待时间我想显示一个向用户等待对话。

我已经尝试创建请等待对话框,然后将HTTP请求发送到服务器。请立即返回,请等待对话框,没有错误,也没有显示任何内容,然后提出HTTP请求,但请否请显示对话框。

如果我不执行HTTP请求并允许执行继续进行对话框。

我认为解决方案可能是在新线程中创建请等待对话框?

我的班级,clsalert源自构造函数中的clsdialog:

    clsAlert::clsAlert(QString strText, QWidget* pParent, bool blnAutoCleanup) : QDialog(pParent), ui(new Ui::clsAlert) {
        ui->setupAlert(this);
        ui->lblText->setText(strText);
        ... set-up geometry ...
        show();
    }

用法示例:

    clsAlert* pPW = new clsAlert(clsAlert::mscszPleaseWait,mpParent);
    int intServer = intCreateSocket(szDestURL, pOutbio);
    ... a lot more source ...
    pPW->cleanup();

最后,我在我的情况下通过添加一个呼叫来解决此问题:

    QCoreApplication::processEvents();

我致电后立即:

    show();