From a693db76c8feb86af3931760995c2fcb08f35062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Sun, 22 Oct 2023 12:33:19 +0800 Subject: [PATCH] update --- example/qml-Qt6/window/HotloadWindow.qml | 24 ++++++++++++++++++------ example/qml/window/HotloadWindow.qml | 24 ++++++++++++++++++------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/example/qml-Qt6/window/HotloadWindow.qml b/example/qml-Qt6/window/HotloadWindow.qml index a8d92b29..321860b5 100644 --- a/example/qml-Qt6/window/HotloadWindow.qml +++ b/example/qml-Qt6/window/HotloadWindow.qml @@ -60,11 +60,11 @@ FluWindow { event.accepted = false return } - if (event.urls.length !== 1) { + var url = getUrlByEvent(event) + if(url === ""){ event.accepted = false return } - var url = event.urls[0].toString() var fileExtension = url.substring(url.lastIndexOf(".") + 1) if (fileExtension !== "qml") { event.accepted = false @@ -74,12 +74,24 @@ FluWindow { } onDropped: (event)=>{ - var path = event.urls[0].toString() - loader.source = path - watcher.path = path - loader.reload() + var url = getUrlByEvent(event) + if(url !== ""){ + loader.source = url + watcher.path = url + loader.reload() + } } } } + function getUrlByEvent(event){ + var url = "" + if (event.urls.length === 0) { + url = "file:///"+event.getDataAsString("text/plain") + }else{ + url = event.urls[0].toString() + } + return url + } + } diff --git a/example/qml/window/HotloadWindow.qml b/example/qml/window/HotloadWindow.qml index 8ab2356e..e2351ffd 100644 --- a/example/qml/window/HotloadWindow.qml +++ b/example/qml/window/HotloadWindow.qml @@ -61,11 +61,11 @@ FluWindow { event.accepted = false return } - if (event.urls.length !== 1) { + var url = getUrlByEvent(event) + if(url === ""){ event.accepted = false return } - var url = event.urls[0].toString() var fileExtension = url.substring(url.lastIndexOf(".") + 1) if (fileExtension !== "qml") { event.accepted = false @@ -75,12 +75,24 @@ FluWindow { } onDropped: (event)=>{ - var path = event.urls[0].toString() - loader.source = path - watcher.path = path - loader.reload() + var url = getUrlByEvent(event) + if(url !== ""){ + loader.source = url + watcher.path = url + loader.reload() + } } } } + function getUrlByEvent(event){ + var url = "" + if (event.urls.length === 0) { + url = "file:///"+event.getDataAsString("text/plain") + }else{ + url = event.urls[0].toString() + } + return url + } + }