Last active
November 20, 2021 13:59
-
-
Save OlegJakushkin/6a380c760247cd148da9aa11a5d751f3 to your computer and use it in GitHub Desktop.
MyBrowser.qml 102
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "handler.h" | |
#include<QDebug> | |
Handler::Handler(QObject *parent) : QObject(parent) | |
{ | |
timesCalled = 0; | |
} | |
void Handler::buttonClicked() | |
{ | |
qInfo("callsed from C++ handler!"); | |
timesCalled++; | |
valueChanged(timesCalled); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef HANDLER_H | |
#define HANDLER_H | |
#include <QObject> | |
class Handler : public QObject | |
{ | |
Q_OBJECT | |
int timesCalled; | |
public: | |
explicit Handler(QObject *parent = nullptr); | |
public slots: | |
void buttonClicked(); | |
signals: | |
void valueChanged(int newValue); | |
}; | |
#endif // HANDLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QGuiApplication> | |
#include <QQmlApplicationEngine> | |
#include <QtQuickControls2/QtQuickControls2> | |
#include <QQmlContext> | |
#include <QtWebView> | |
#include "handler.h" | |
int main(int argc, char *argv[]) | |
{ | |
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) | |
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | |
#endif | |
QGuiApplication app(argc, argv); | |
QtWebView::initialize(); | |
QQmlApplicationEngine engine; | |
const QUrl url(QStringLiteral("qrc:/main.qml")); | |
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, | |
&app, [url](QObject *obj, const QUrl &objUrl) { | |
if (!obj && url == objUrl) | |
QCoreApplication::exit(-1); | |
}, Qt::QueuedConnection); | |
auto ctx = engine.rootContext(); | |
auto handler = Handler(); | |
ctx->setContextProperty("handler", &handler); | |
engine.load(url); | |
auto object = engine.rootObjects()[0]; | |
auto myButton = object->findChild<QObject*>("myButton3"); | |
QObject::connect(myButton, SIGNAL(clicked()), &handler, SLOT(buttonClicked())); | |
return app.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.15 | |
import QtQuick.Window 2.15 | |
import './' as MyComponents | |
Window { | |
width: 640 | |
height: 480 | |
visible: true | |
title: qsTr("my test app") | |
MyComponents.MyBrowser { | |
id: myBrowser | |
anchors.fill: parent | |
} | |
MyComponents.MyApp { | |
id: myComponent | |
anchors.fill: parent | |
} | |
Connections { | |
target: handler | |
onValueChanged: { | |
console.log("Data: " + newValue) | |
var str_in = "Data: " + newValue | |
myComponent.pulicText.text = "Changed to: " + str_in | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.0 | |
import QtQuick.Controls 2.15 | |
Item { | |
property Text pulicText: textToChange | |
id: groupBox | |
x: 0 | |
y: 0 | |
width: 215 | |
height: 137 | |
Button { | |
x: 104 | |
y: 86 | |
text: 'My button 1!' | |
anchors.right: parent.right | |
anchors.bottom: parent.bottom | |
anchors.rightMargin: 5 | |
anchors.bottomMargin: 5 | |
onClicked: groupBox.f() | |
} | |
Button { | |
text: 'My button 2!' | |
anchors.left: parent.left | |
anchors.top: parent.top | |
anchors.leftMargin: 5 | |
anchors.topMargin: 5 | |
onClicked: {console.log("hello from 2!")} | |
} | |
Button { | |
text: "My button 3!" | |
objectName: "myButton3" | |
id: myButton3 | |
anchors.left: parent.horizontalCenter | |
anchors.right: parent.horizontalCenter | |
anchors.top: parent.verticalCenter | |
anchors.bottom: parent.verticalCenter | |
anchors.rightMargin: -53 | |
anchors.bottomMargin: -17 | |
anchors.leftMargin: -54 | |
anchors.topMargin: -18 | |
} | |
Text { | |
objectName: "textToChange" | |
id: textToChange | |
text: "beforeChange" | |
anchors.left: parent.horizontalCenter | |
anchors.right: parent.horizontalCenter | |
anchors.top: parent.verticalCenter | |
anchors.bottom: parent.verticalCenter | |
anchors.rightMargin: -153 | |
anchors.leftMargin: -52 | |
anchors.bottomMargin: -48 | |
anchors.topMargin: 14 | |
} | |
function f() {console.log("hello! from groupBox")} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.0 | |
import QtWebView 1.1 | |
import QtQuick.Controls 2.15 | |
Item { | |
id: item1 | |
anchors.fill: parent | |
WebView { | |
id: webb | |
anchors.fill: parent | |
anchors.topMargin: 25 | |
url: "http://www.google.com" | |
} | |
Rectangle { | |
id: rectangle | |
height: 25 | |
color: "#ff11d6" | |
anchors.left: parent.left | |
anchors.right: parent.right | |
anchors.top: parent.top | |
anchors.topMargin: 0 | |
anchors.rightMargin: 0 | |
anchors.leftMargin: 0 | |
TextField { | |
id: textInput | |
height: 20 | |
text: qsTr("Text Input") | |
anchors.left: parent.left | |
anchors.right: parent.right | |
anchors.top: parent.top | |
font.pixelSize: 12 | |
anchors.topMargin: 2 | |
anchors.leftMargin: 8 | |
anchors.rightMargin: 89 | |
placeholderText: qsTr("Text Field") | |
Connections { | |
target: textInput | |
onEditingFinished: webb.url = textInput.text | |
} | |
} | |
Button { | |
id: button | |
x: 556 | |
width: 75 | |
height: 20 | |
text: qsTr("Go!") | |
anchors.right: parent.right | |
anchors.top: parent.top | |
anchors.topMargin: 1 | |
anchors.rightMargin: 9 | |
Connections { | |
target: button | |
onClicked: webb.url = textInput.text | |
} | |
} | |
} | |
} | |
/*##^## | |
Designer { | |
D{i:0;autoSize:true;formeditorZoom:1.25;height:480;width:640}D{i:1}D{i:4}D{i:3}D{i:6} | |
D{i:5}D{i:2} | |
} | |
##^##*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QT += quick webview webenginewidgets | |
CONFIG += c++11 | |
# You can make your code fail to compile if it uses deprecated APIs. | |
# In order to do so, uncomment the following line. | |
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | |
SOURCES += \ | |
handler.cpp \ | |
main.cpp | |
RESOURCES += qml.qrc | |
# Additional import path used to resolve QML modules in Qt Creator's code model | |
QML_IMPORT_PATH = | |
# Additional import path used to resolve QML modules just for Qt Quick Designer | |
QML_DESIGNER_IMPORT_PATH = | |
# Default rules for deployment. | |
qnx: target.path = /tmp/$${TARGET}/bin | |
else: unix:!android: target.path = /opt/$${TARGET}/bin | |
!isEmpty(target.path): INSTALLS += target | |
HEADERS += \ | |
handler.h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment