Search code examples
qtsignals-slots

signal-slot in Qt : emit is located in the slot method


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


Solution

  • 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