Paul
Paul

Reputation: 6176

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

Upvotes: 0

Views: 679

Answers (1)

Will
Will

Reputation: 871

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

Upvotes: 4

Related Questions