QT 几个异步模式对话框

发布于 2024-12-27 12:43:05 字数 330 浏览 2 评论 0原文

在我的程序中,有一个循环,其中有类似的内容:

QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(path)));

该函数被调用多次。在“回复完成”时,程序显示模式对话框(例如,常规 QDialog)。问题是我希望对话一个接一个地出现,而不是像现在这样同时出现。

我尝试对每个“等待”对话框使用

QList<QEventLoop *> stack;

一个 QEventLoop。但在我看来,这是一个糟糕的解决方案。

In my program there is a cycle in which there is something like that:

QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(path)));

This function is called several times. On "reply finished" the program displays modal dialog (for example, regular QDialog). The problem is that I want dialogues to appear one after another, rather than all at once, together, as it happened now.

I tried to use

QList<QEventLoop *> stack;

One QEventLoop for every "waiting" dialog. But it seems to me that this is bad solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江城子 2025-01-03 12:43:05

您不需要使用QEventLoop

如果对话框是模式对话框,那么它会阻止所有其他对话框获取输入。在这种情况下,您应该在对话框关闭时发送信号。例如,您可以使用QDialog::Finished(int)。信号接收者正是打开对话框的对象。

//slot
void showDialog(){
 if(msg.size() <= 0)
  return;
 //create dialog here
 connect(createdDialog, SIGNAL(finished(int)), this, SLOT(showDialog()));
}

您可以为第一条消息自行调用此方法。

如果对话框是非模态的,那么您需要使用单次QTimer来延迟下一个对话框。
基本上,每次显示对话框时,您都会计算希望显示另一个对话框的最早时间,并根据该时间设置一个计时器。当它被触发时,您检查消息并打开对话框,依此类推...

但是我想知道对话框是否是显示连续输入信息的最佳方式。

You don't need to use QEventLoop.

If the dialog is modal, then it prevent all others to get input. In this case you should send a signal when the dialog is closed. You can use QDialog::Finished(int) for example. The signal receiver is non other than the object which opened the dialog.

//slot
void showDialog(){
 if(msg.size() <= 0)
  return;
 //create dialog here
 connect(createdDialog, SIGNAL(finished(int)), this, SLOT(showDialog()));
}

And you can call this method yourself for the first message.

If the dialog is non modal, then you need to use singleshot QTimer to delays next dialog.
Basically each time you display a dialog, you compute the earliest time you want another dialog to be shown and you set up a timer with this time. When it is fired, you check for a message and open a dialog, and so on...

However I wonder if dialogs are the best way to show continuous input of information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文