[Interest] qml <--> c++

Tony Rietwyk tony at rightsoft.com.au
Sun Feb 28 08:02:05 CET 2016


Hi Nicolas, 

 

I can see you left out Q_OBJECT on CustomWebView.  Not idea whether the rest will work or not to achieve your aim. 

 

Tony

 

 

From: Interest [mailto:interest-bounces+tony=rightsoft.com.au at qt-project.org] On Behalf Of jagernicolas at legtux.org
Sent: Sunday, 28 February 2016 3:16 PM
To: interest at qt-project.org
Subject: [Interest] qml <--> c++

 

Hi,

in my main.qml I have this code :

        WebEngineView {
            id: webview
            url: "192.168.2.1"
            anchors.fill: parent
            onNewViewRequested: {
                var w_ = crecreateObject()
                request.openIn(appWin.w_)
            }
        }

when onNewViewRequested is called, I would like to open the url of the request in the the same WebEngineView, not creating a new WebEngine. So I was thinking to create some class who inherits of WebEngine.

I didn't found any class called WebEngine I can inherit, or I did not found the header... but I found QWebEngine, so I did this :

// in CustomWebView.h
#pragma once
#include <QtWebEngineWidgets/QtWebEngineWidgets>

class CustomWebView : public QWebEngineView
{
    Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)

public:
    CustomWebView(QWidget *parent);
    CustomWebView();

};

I register the qml inside my main.cpp : 

    qmlRegisterType<CustomWebView>("customWebView", 1, 0, "CustomWebView");

and in my main.qml I did some changes/add :

import CustomWebView 1.0

        CustomWebView {
            id: webview
            url: "192.168.2.1"
            anchors.fill: parent
//            onNewViewRequested: {
//                var w_ = crecreateObject()
//                request.openIn(appWin.w_)
//            }
        }

but, when I compiled, I got the msg : Cannot assign to non-existent property "url"

obviously, I didi some mistake, but where ?

Regards,
Nicolas

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160228/18e2469d/attachment.html>


More information about the Interest mailing list