[Interest] Fw: qml <--> c++

Nicolas Jäger jagernicolas at legtux.org
Wed Mar 2 04:51:06 CET 2016


Hi Tony,
yesterday when I compiled with Q_OBJECT I got error, but today it works, I have no idea why...but
yes I agree I should have Q_OBJECT. But this doesn't solve my problem. Also I guess I can rewrite a
new class who inherits of QWebEngineView with all Q_PROPERTY and stuff to make it works as I want,
but since we are talking about C++ I expecting to be able to inherits the QML code associated to the
class (QWebEngineView), instead of rewrittng all QML code (for that class) from scratch.

regards,
Nicolas

"Tony Rietwyk" wrote:

> 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
> 
>  
>   

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



More information about the Interest mailing list