私はBusyIndicatorを持っています。BusyIndicatorは、計算が重なっている間に回転し、計算が終了すると停止します。ControllerクラスへのWorkerScriptのアクセス
私はWorkerScriptが正しい方法だと思ったが、from hereだと思ったが、.jsファイル内のセカンダリ(計算スレッド)がプライマリ.qmlスレッドのオブジェクトにアクセスできないようだ。
これは、私のすべての計算が、プライマリスレッドによってインスタンス化されたコントローラC++で定義されたQObjectによって実行されるため、問題があります。ここで
は私のコードです:
main.qml
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.0
import QtQuick.Controls.Styles 1.2
import QtQuick.Dialogs 1.2
import LcQml 1.0
ApplicationWindow
{
id: window
UiController
{
id: uiController
}
WorkerScript
{
id: importScanWorkerScript
source: "importScanWorkerScript.js"
onMessage:
{
busyIndicator.running = false;
}
}
FileDialog
{
id: importScanDialog
visible: false
title: "Import a [scan] file"
folder: "MyScannedScenesFolder"
nameFilters: [ "STL files (*stl)" ]
selectedNameFilter: "STL files (*stl)"
onAccepted:
{
importScanWorkerScript.sendMessage({'filepath': importScanDialog.fileUrl})
busyIndicator.running = true;
}
}
BusyIndicator
{
id: busyIndicator
running: false
anchors.centerIn: parent
}
}
importScanWorkerScript.js
WorkerScript.onMessage = function(message)
{
uiController.onImportScanDevMenuClicked(message.filepath);
WorkerScript.sendMessage()
}
鉛:がuiControllerがimportScanWorkerScripで定義されていませんt.js。
WorkerScriptは単純な状況のみを処理できることを理解する必要がありますか?
ご提案uiController.doSomething(で)とuiController.doSomethingAnother()はなし、UIスレッドで処理されます?私の場合、それはuiController.doSomething()とuiController.doSomethingAnother()はバックグラウンドスレッドでのコンピュータである必要があり、実際の重いfonctionsあることが判明... – arennuit
ああ、[OK]を、今私はそれを参照してください。ここでの最善のアプローチは、QThreadをC++コードで使用して重いタスクを実行することです。 JavascriptコードでC++タスクを実行する意味はありませんが、WorkerScriptにオブジェクトを渡すことはできません。 – folibis
私はWorkerScript leがその時に有益であることを理解していません...誰がjsで重度の転流を実行したいですか?とにかく助けてくれてありがとう! – arennuit