QML中呼叫C++耗時操作造成阻塞的解決辦法
阿新 • • 發佈:2018-12-21
在QML中經常會呼叫用C++寫的比較耗時的操作時,一般會造成介面的卡死。剛開始的時候是想著是不是可以在QML中開闢新執行緒,一查還真有,WorkerScript。但這玩意兒有點坑的是你不能訪問其他物件的屬性、方法,官方原文是這樣寫的: Since the WorkerScript.onMessage() function is run in a separate thread, the JavaScript file is evaluated in a context separate from the main QML engine. This means that unlike an ordinary JavaScript file that is imported into QML, the script.js in the above example cannot access the properties, methods or other attributes of the QML item, nor can it access any context properties set on the QML object through QQmlContext.