add book
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(5-JsIndirectImprt VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app5-JsIndirectImprt
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app5-JsIndirectImprt
|
||||
URI 5-JsIndirectImprt
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml utilities1.js utilities2.js
|
||||
)
|
||||
|
||||
set_target_properties(app5-JsIndirectImprt PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(app5-JsIndirectImprt
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app5-JsIndirectImprt
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
32
Qt6QMLBeginnersCode/6.Javascript/5-JsIndirectImprt/Main.qml
Normal file
32
Qt6QMLBeginnersCode/6.Javascript/5-JsIndirectImprt/Main.qml
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
import "utilities1.js" as Utilities1
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("Javascript Import Demo")
|
||||
|
||||
Rectangle {
|
||||
width: 300
|
||||
height: 100
|
||||
color: "yellowgreen"
|
||||
anchors.centerIn: parent
|
||||
|
||||
Text {
|
||||
text: "Click Me"
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
//console.log("The ages yield: " + Utilities1.combineAges(33,17))
|
||||
value = Utilities1.add(33,17) //Error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
Qt6QMLBeginnersCode/6.Javascript/5-JsIndirectImprt/main.cpp
Normal file
20
Qt6QMLBeginnersCode/6.Javascript/5-JsIndirectImprt/main.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("5-JsIndirectImprt", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
.import "utilities2.js" as Utilities2
|
||||
|
||||
function greeting()
|
||||
{
|
||||
console.log("Hello there from external JS file: utilities1.js")
|
||||
}
|
||||
|
||||
function combineAges( age1, age2)
|
||||
{
|
||||
return Utilities2.add(age1,age2)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
function add(a,b) {
|
||||
console.log("Method from utilities2.js called")
|
||||
return a + b
|
||||
}
|
||||
Reference in New Issue
Block a user