How to make custom QML component visible?
I am quite new to QT and I need to create QML component for viewing web-pages with posibility of tracking click on some links. I created MyWebView class inheritated from QWebView
mywebview.h
#ifndef MYWEBVIEW_H
#define MYWEBVIEW_H
#include <QApplication>
#include <QWebFrame>
#include <QWebPage>
#include <QWebView>
#include <QUrl>
#include <QJsonDocument>
#include <QJsonObject>
#include <QObject>
#include <QProcess>
class MyWebView: public QWebView {
Q_OBJECT
public:
explicit MyWebView();
public slots:
void onJavaScriptWindowObjectCleared();
void trackOpen(QString metadata);
void trackTurn(QString metadata);
mywebview.cpp
#include "mywebview.h"
MyWebView::MyWebView(){
connect(this->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(onJavaScriptWindowObjectCleared()));
qInfo() << "MyWebView Created";
}
void MyWebView::onJavaScriptWindowObjectCleared(){
this->page()->mainFrame()->evaluateJavaScript("console.log('MyWebView init!')");
}
void MyWebView::trackOpen(QString metadata){
qWarning() << "Open";
}
void MyWebView::trackTurn(QString metadata) {
qWarning() << "Turn";
}
Main program using this component:
main.cpp
#include "mywebview.h"
#include <QtQuick/QQuickView>
#include <QApplication>
#include <QtQuick/QQuickItem>
#include <QQmlApplicationEngine>
#include <QtWebView/QtWebView>
int main(int argc, char *argv)
{
QApplication app(argc, argv);
qmlRegisterType<MyWebView>("MyWebView", 1, 0, "MyWebView");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/app.qml")));
return app.exec();
}
app.qml
import MyWebView 1.0
import QtQuick 2.0
import QtWebKit 3.0
import QtQuick.Controls 1.4
import QtQuick.Window 2.0
ApplicationWindow {
id: window
visible: true
title: "Window"
width: 640
height: 480
MyWebView {
id: webview
url: "http://127.0.0.1"
}
}
So, while running this application I can see only clean window and now content inside it. Investigating of local web server's logs (127.0.0.1) I found that program makes requests to web server. How to make my component visible?
Thanks in advance
c++ qt qml
add a comment |
I am quite new to QT and I need to create QML component for viewing web-pages with posibility of tracking click on some links. I created MyWebView class inheritated from QWebView
mywebview.h
#ifndef MYWEBVIEW_H
#define MYWEBVIEW_H
#include <QApplication>
#include <QWebFrame>
#include <QWebPage>
#include <QWebView>
#include <QUrl>
#include <QJsonDocument>
#include <QJsonObject>
#include <QObject>
#include <QProcess>
class MyWebView: public QWebView {
Q_OBJECT
public:
explicit MyWebView();
public slots:
void onJavaScriptWindowObjectCleared();
void trackOpen(QString metadata);
void trackTurn(QString metadata);
mywebview.cpp
#include "mywebview.h"
MyWebView::MyWebView(){
connect(this->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(onJavaScriptWindowObjectCleared()));
qInfo() << "MyWebView Created";
}
void MyWebView::onJavaScriptWindowObjectCleared(){
this->page()->mainFrame()->evaluateJavaScript("console.log('MyWebView init!')");
}
void MyWebView::trackOpen(QString metadata){
qWarning() << "Open";
}
void MyWebView::trackTurn(QString metadata) {
qWarning() << "Turn";
}
Main program using this component:
main.cpp
#include "mywebview.h"
#include <QtQuick/QQuickView>
#include <QApplication>
#include <QtQuick/QQuickItem>
#include <QQmlApplicationEngine>
#include <QtWebView/QtWebView>
int main(int argc, char *argv)
{
QApplication app(argc, argv);
qmlRegisterType<MyWebView>("MyWebView", 1, 0, "MyWebView");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/app.qml")));
return app.exec();
}
app.qml
import MyWebView 1.0
import QtQuick 2.0
import QtWebKit 3.0
import QtQuick.Controls 1.4
import QtQuick.Window 2.0
ApplicationWindow {
id: window
visible: true
title: "Window"
width: 640
height: 480
MyWebView {
id: webview
url: "http://127.0.0.1"
}
}
So, while running this application I can see only clean window and now content inside it. Investigating of local web server's logs (127.0.0.1) I found that program makes requests to web server. How to make my component visible?
Thanks in advance
c++ qt qml
Why do you reinvent the wheel? Creating an item as a rectangle is simple but a browser is too complex a task. You must use WebEngineView doc.qt.io/qt-5/qml-qtwebengine-webengineview.html
– eyllanesc
Nov 27 '18 at 16:44
I need to make possible running C++ procedure from javascript on the web page. As I can see WebEngineView allows to run Javascript only, but it's neccessary to calculate statistics inside the C++ app.
– nickolai_by
Nov 28 '18 at 15:28
QML can make calls to C++ code so I do not see that that is the problem, if you point out that you want to do exactly I could point out what to do (ie what C++ code you want to do and when you want to call it), QWebView is a Qt Widget that QML can not handle, does not know how to ask you to paint on the window so you can not observe it, QML expects Items, not Qt Widgets.
– eyllanesc
Nov 28 '18 at 19:16
My web-page has couple of javascript handlers for events (opening new link, clicking on buttons) and I need to collect statistics in my application from this events including metadata. In other words, javascript function should call C++ procedure in my app with array of data as a param.
– nickolai_by
Nov 29 '18 at 8:19
add a comment |
I am quite new to QT and I need to create QML component for viewing web-pages with posibility of tracking click on some links. I created MyWebView class inheritated from QWebView
mywebview.h
#ifndef MYWEBVIEW_H
#define MYWEBVIEW_H
#include <QApplication>
#include <QWebFrame>
#include <QWebPage>
#include <QWebView>
#include <QUrl>
#include <QJsonDocument>
#include <QJsonObject>
#include <QObject>
#include <QProcess>
class MyWebView: public QWebView {
Q_OBJECT
public:
explicit MyWebView();
public slots:
void onJavaScriptWindowObjectCleared();
void trackOpen(QString metadata);
void trackTurn(QString metadata);
mywebview.cpp
#include "mywebview.h"
MyWebView::MyWebView(){
connect(this->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(onJavaScriptWindowObjectCleared()));
qInfo() << "MyWebView Created";
}
void MyWebView::onJavaScriptWindowObjectCleared(){
this->page()->mainFrame()->evaluateJavaScript("console.log('MyWebView init!')");
}
void MyWebView::trackOpen(QString metadata){
qWarning() << "Open";
}
void MyWebView::trackTurn(QString metadata) {
qWarning() << "Turn";
}
Main program using this component:
main.cpp
#include "mywebview.h"
#include <QtQuick/QQuickView>
#include <QApplication>
#include <QtQuick/QQuickItem>
#include <QQmlApplicationEngine>
#include <QtWebView/QtWebView>
int main(int argc, char *argv)
{
QApplication app(argc, argv);
qmlRegisterType<MyWebView>("MyWebView", 1, 0, "MyWebView");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/app.qml")));
return app.exec();
}
app.qml
import MyWebView 1.0
import QtQuick 2.0
import QtWebKit 3.0
import QtQuick.Controls 1.4
import QtQuick.Window 2.0
ApplicationWindow {
id: window
visible: true
title: "Window"
width: 640
height: 480
MyWebView {
id: webview
url: "http://127.0.0.1"
}
}
So, while running this application I can see only clean window and now content inside it. Investigating of local web server's logs (127.0.0.1) I found that program makes requests to web server. How to make my component visible?
Thanks in advance
c++ qt qml
I am quite new to QT and I need to create QML component for viewing web-pages with posibility of tracking click on some links. I created MyWebView class inheritated from QWebView
mywebview.h
#ifndef MYWEBVIEW_H
#define MYWEBVIEW_H
#include <QApplication>
#include <QWebFrame>
#include <QWebPage>
#include <QWebView>
#include <QUrl>
#include <QJsonDocument>
#include <QJsonObject>
#include <QObject>
#include <QProcess>
class MyWebView: public QWebView {
Q_OBJECT
public:
explicit MyWebView();
public slots:
void onJavaScriptWindowObjectCleared();
void trackOpen(QString metadata);
void trackTurn(QString metadata);
mywebview.cpp
#include "mywebview.h"
MyWebView::MyWebView(){
connect(this->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(onJavaScriptWindowObjectCleared()));
qInfo() << "MyWebView Created";
}
void MyWebView::onJavaScriptWindowObjectCleared(){
this->page()->mainFrame()->evaluateJavaScript("console.log('MyWebView init!')");
}
void MyWebView::trackOpen(QString metadata){
qWarning() << "Open";
}
void MyWebView::trackTurn(QString metadata) {
qWarning() << "Turn";
}
Main program using this component:
main.cpp
#include "mywebview.h"
#include <QtQuick/QQuickView>
#include <QApplication>
#include <QtQuick/QQuickItem>
#include <QQmlApplicationEngine>
#include <QtWebView/QtWebView>
int main(int argc, char *argv)
{
QApplication app(argc, argv);
qmlRegisterType<MyWebView>("MyWebView", 1, 0, "MyWebView");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/app.qml")));
return app.exec();
}
app.qml
import MyWebView 1.0
import QtQuick 2.0
import QtWebKit 3.0
import QtQuick.Controls 1.4
import QtQuick.Window 2.0
ApplicationWindow {
id: window
visible: true
title: "Window"
width: 640
height: 480
MyWebView {
id: webview
url: "http://127.0.0.1"
}
}
So, while running this application I can see only clean window and now content inside it. Investigating of local web server's logs (127.0.0.1) I found that program makes requests to web server. How to make my component visible?
Thanks in advance
c++ qt qml
c++ qt qml
asked Nov 27 '18 at 16:27
nickolai_bynickolai_by
1
1
Why do you reinvent the wheel? Creating an item as a rectangle is simple but a browser is too complex a task. You must use WebEngineView doc.qt.io/qt-5/qml-qtwebengine-webengineview.html
– eyllanesc
Nov 27 '18 at 16:44
I need to make possible running C++ procedure from javascript on the web page. As I can see WebEngineView allows to run Javascript only, but it's neccessary to calculate statistics inside the C++ app.
– nickolai_by
Nov 28 '18 at 15:28
QML can make calls to C++ code so I do not see that that is the problem, if you point out that you want to do exactly I could point out what to do (ie what C++ code you want to do and when you want to call it), QWebView is a Qt Widget that QML can not handle, does not know how to ask you to paint on the window so you can not observe it, QML expects Items, not Qt Widgets.
– eyllanesc
Nov 28 '18 at 19:16
My web-page has couple of javascript handlers for events (opening new link, clicking on buttons) and I need to collect statistics in my application from this events including metadata. In other words, javascript function should call C++ procedure in my app with array of data as a param.
– nickolai_by
Nov 29 '18 at 8:19
add a comment |
Why do you reinvent the wheel? Creating an item as a rectangle is simple but a browser is too complex a task. You must use WebEngineView doc.qt.io/qt-5/qml-qtwebengine-webengineview.html
– eyllanesc
Nov 27 '18 at 16:44
I need to make possible running C++ procedure from javascript on the web page. As I can see WebEngineView allows to run Javascript only, but it's neccessary to calculate statistics inside the C++ app.
– nickolai_by
Nov 28 '18 at 15:28
QML can make calls to C++ code so I do not see that that is the problem, if you point out that you want to do exactly I could point out what to do (ie what C++ code you want to do and when you want to call it), QWebView is a Qt Widget that QML can not handle, does not know how to ask you to paint on the window so you can not observe it, QML expects Items, not Qt Widgets.
– eyllanesc
Nov 28 '18 at 19:16
My web-page has couple of javascript handlers for events (opening new link, clicking on buttons) and I need to collect statistics in my application from this events including metadata. In other words, javascript function should call C++ procedure in my app with array of data as a param.
– nickolai_by
Nov 29 '18 at 8:19
Why do you reinvent the wheel? Creating an item as a rectangle is simple but a browser is too complex a task. You must use WebEngineView doc.qt.io/qt-5/qml-qtwebengine-webengineview.html
– eyllanesc
Nov 27 '18 at 16:44
Why do you reinvent the wheel? Creating an item as a rectangle is simple but a browser is too complex a task. You must use WebEngineView doc.qt.io/qt-5/qml-qtwebengine-webengineview.html
– eyllanesc
Nov 27 '18 at 16:44
I need to make possible running C++ procedure from javascript on the web page. As I can see WebEngineView allows to run Javascript only, but it's neccessary to calculate statistics inside the C++ app.
– nickolai_by
Nov 28 '18 at 15:28
I need to make possible running C++ procedure from javascript on the web page. As I can see WebEngineView allows to run Javascript only, but it's neccessary to calculate statistics inside the C++ app.
– nickolai_by
Nov 28 '18 at 15:28
QML can make calls to C++ code so I do not see that that is the problem, if you point out that you want to do exactly I could point out what to do (ie what C++ code you want to do and when you want to call it), QWebView is a Qt Widget that QML can not handle, does not know how to ask you to paint on the window so you can not observe it, QML expects Items, not Qt Widgets.
– eyllanesc
Nov 28 '18 at 19:16
QML can make calls to C++ code so I do not see that that is the problem, if you point out that you want to do exactly I could point out what to do (ie what C++ code you want to do and when you want to call it), QWebView is a Qt Widget that QML can not handle, does not know how to ask you to paint on the window so you can not observe it, QML expects Items, not Qt Widgets.
– eyllanesc
Nov 28 '18 at 19:16
My web-page has couple of javascript handlers for events (opening new link, clicking on buttons) and I need to collect statistics in my application from this events including metadata. In other words, javascript function should call C++ procedure in my app with array of data as a param.
– nickolai_by
Nov 29 '18 at 8:19
My web-page has couple of javascript handlers for events (opening new link, clicking on buttons) and I need to collect statistics in my application from this events including metadata. In other words, javascript function should call C++ procedure in my app with array of data as a param.
– nickolai_by
Nov 29 '18 at 8:19
add a comment |
1 Answer
1
active
oldest
votes
Your item needs to be anchored to the parent:
MyWebView {
id: webview
url: "http://127.0.0.1"
anchors.fill: parent
}
I tried, but I've got 'Cannot assign to non-existent property "anchors"'
– nickolai_by
Nov 28 '18 at 15:29
that is weird. Can you for the sake of at least seeing something assign awidth
andheight
?
– Amfasis
Nov 28 '18 at 19:21
Cannot, 'Invalid property assignment: "width" is a read-only property'
– nickolai_by
Nov 29 '18 at 9:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53504041%2fhow-to-make-custom-qml-component-visible%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your item needs to be anchored to the parent:
MyWebView {
id: webview
url: "http://127.0.0.1"
anchors.fill: parent
}
I tried, but I've got 'Cannot assign to non-existent property "anchors"'
– nickolai_by
Nov 28 '18 at 15:29
that is weird. Can you for the sake of at least seeing something assign awidth
andheight
?
– Amfasis
Nov 28 '18 at 19:21
Cannot, 'Invalid property assignment: "width" is a read-only property'
– nickolai_by
Nov 29 '18 at 9:00
add a comment |
Your item needs to be anchored to the parent:
MyWebView {
id: webview
url: "http://127.0.0.1"
anchors.fill: parent
}
I tried, but I've got 'Cannot assign to non-existent property "anchors"'
– nickolai_by
Nov 28 '18 at 15:29
that is weird. Can you for the sake of at least seeing something assign awidth
andheight
?
– Amfasis
Nov 28 '18 at 19:21
Cannot, 'Invalid property assignment: "width" is a read-only property'
– nickolai_by
Nov 29 '18 at 9:00
add a comment |
Your item needs to be anchored to the parent:
MyWebView {
id: webview
url: "http://127.0.0.1"
anchors.fill: parent
}
Your item needs to be anchored to the parent:
MyWebView {
id: webview
url: "http://127.0.0.1"
anchors.fill: parent
}
answered Nov 27 '18 at 19:00
AmfasisAmfasis
653414
653414
I tried, but I've got 'Cannot assign to non-existent property "anchors"'
– nickolai_by
Nov 28 '18 at 15:29
that is weird. Can you for the sake of at least seeing something assign awidth
andheight
?
– Amfasis
Nov 28 '18 at 19:21
Cannot, 'Invalid property assignment: "width" is a read-only property'
– nickolai_by
Nov 29 '18 at 9:00
add a comment |
I tried, but I've got 'Cannot assign to non-existent property "anchors"'
– nickolai_by
Nov 28 '18 at 15:29
that is weird. Can you for the sake of at least seeing something assign awidth
andheight
?
– Amfasis
Nov 28 '18 at 19:21
Cannot, 'Invalid property assignment: "width" is a read-only property'
– nickolai_by
Nov 29 '18 at 9:00
I tried, but I've got 'Cannot assign to non-existent property "anchors"'
– nickolai_by
Nov 28 '18 at 15:29
I tried, but I've got 'Cannot assign to non-existent property "anchors"'
– nickolai_by
Nov 28 '18 at 15:29
that is weird. Can you for the sake of at least seeing something assign a
width
and height
?– Amfasis
Nov 28 '18 at 19:21
that is weird. Can you for the sake of at least seeing something assign a
width
and height
?– Amfasis
Nov 28 '18 at 19:21
Cannot, 'Invalid property assignment: "width" is a read-only property'
– nickolai_by
Nov 29 '18 at 9:00
Cannot, 'Invalid property assignment: "width" is a read-only property'
– nickolai_by
Nov 29 '18 at 9:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53504041%2fhow-to-make-custom-qml-component-visible%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why do you reinvent the wheel? Creating an item as a rectangle is simple but a browser is too complex a task. You must use WebEngineView doc.qt.io/qt-5/qml-qtwebengine-webengineview.html
– eyllanesc
Nov 27 '18 at 16:44
I need to make possible running C++ procedure from javascript on the web page. As I can see WebEngineView allows to run Javascript only, but it's neccessary to calculate statistics inside the C++ app.
– nickolai_by
Nov 28 '18 at 15:28
QML can make calls to C++ code so I do not see that that is the problem, if you point out that you want to do exactly I could point out what to do (ie what C++ code you want to do and when you want to call it), QWebView is a Qt Widget that QML can not handle, does not know how to ask you to paint on the window so you can not observe it, QML expects Items, not Qt Widgets.
– eyllanesc
Nov 28 '18 at 19:16
My web-page has couple of javascript handlers for events (opening new link, clicking on buttons) and I need to collect statistics in my application from this events including metadata. In other words, javascript function should call C++ procedure in my app with array of data as a param.
– nickolai_by
Nov 29 '18 at 8:19