Qt 中的信号槽:emit 位于 slot 方法中

发布于 2024-12-18 06:29:50 字数 387 浏览 5 评论 0原文

我正在读一本关于Qt的书,在信号槽函数的一个示例中,槽方法内部有一个emit方法...所以这变成了一个无限循环...我真的不明白如何停止它:

connect(webView, SIGNAL(urlChanged(const QUrl&)), 
    this, SLOT(urlChange(const QUrl&));

然后我们就有了这个功能:

void BrowserWindow::urlChange(const QUrl &url)
{
    emit urlChanged(url);
    progressLabel->setText(tr("Loading"));
}

谢谢

i'm reading a book about Qt, in one of the examples of a signal-slot function, there is the emit method located inside the slot method... So this becomes an infinite loop... i don't really understand how to stop it :

connect(webView, SIGNAL(urlChanged(const QUrl&)), 
    this, SLOT(urlChange(const QUrl&));

and we then have the function :

void BrowserWindow::urlChange(const QUrl &url)
{
    emit urlChanged(url);
    progressLabel->setText(tr("Loading"));
}

Thanks

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

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

发布评论

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

评论(1

泛滥成性 2024-12-25 06:29:50

什么是网络视图? (它是同一类型吗?)

连接正在将一个实例与此插槽连接 - 它可能没有连接它自己的实例。

如果是的

connect(this, SIGNAL(urlChanged(const QUrl&)), 
        this, SLOT(urlChange(const QUrl&));

话那就是无限循环

What is webView? (is it the same type?)

The connect is connecting one instance with this slot - its probably not connecting its own instance.

If it was

connect(this, SIGNAL(urlChanged(const QUrl&)), 
        this, SLOT(urlChange(const QUrl&));

then that would be an infinite loop

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