Quantcast
Viewing all articles
Browse latest Browse all 4972

Facing error while connecting a QML child object signal to another object's slot

The setup I am using is Qt 5.1 + Qt Quick 2 + Qt Quick Controls. I have a Main QML window. I handle the processing part of the Main window in a C++ class called AppController. Now, Main has a button “Authorize”, clicking which should spawn another Authorizer QML window. The way I have handled this is to invoke AppController::launchOAuth2Browser() slot by connecting it to Main.Authorize.clicked() signal. The slot creates an instance of Authorizer QML using the new QQmlApplicationEngine. Thus, the C++ class of Main handles the creation of the other QML window (which I don’t know is the best way to do it). Now, Authorizer window has a child object WebView. I need to connect the WebView.urlChanged() signal to an OAuth2::onBrowserUrlChanged() slot. Here is the code that handles the window creation part, and the connection part. void AppController::launchOauth2Browser(QUrl& url) {     QQmlApplicationEngine *engine = new QQmlApplicationEngine("OAuth2Browser.qml");     QQmlContext *context = engine->rootContext();     context->setContextProperty("oauth2", m_oauth2);       QObject *topLevel = engine->rootObjects().value(0);     QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);     window->show();       QWebView *browser = topLevel->findChild<QWebView *>("Browser");     qDebug() << "connecting urlChanged to onBrowserUrlChanged";     QObject::connect(browser, &QWebView::urlChanged, m_oauth2, &OAuth2::onBrowserUrlChanged);     browser->setUrl(url);       qDebug() << "connecting closeBrowser to close";     QObject::connect(m_oauth2, &OAuth2::closeBrowser, window, &QQuickWindow::close); } However, when this code runs, it gives error at the following line:     QObject::connect(browser, &QWebView::urlChanged, m_oauth2, &OAuth2::onBrowserUrlChanged); The error says: QObject::connect: invalid null parameter Here is the Authorizer window code: Window {     id: window     width: 500     height: 500       ColumnLayout {         anchors.fill: parent           WebView {             objectName: "Browser"             id: browser             Layout.fillHeight: true             Layout.fillWidth: true         }           Label {             id: loadingStatus             Layout.fillWidth: true             text: browser.loadProgress + "% loaded."         }     } } I know that m_oauth2 is not null – it has already been referenced earlier. So, browser has to be null, the reason of which I don’t know. I have already created the QML window. Shouldn’t the child objects be created with it as well? Aside from that, where do you think I should have handled the new window creation? from the Main QML window itself, using dynamic window management, or the current C++ implementation which has the AppController have to deal with UI code? P.S.: Look at the first reply (posted by me) that explains the now changed error.

Viewing all articles
Browse latest Browse all 4972

Trending Articles