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...@qt-project.org] 
On Behalf Of jagernico...@legtux.org
Sent: Sunday, 28 February 2016 3:16 PM
To: interest@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

 

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to