Giter Site home page Giter Site logo

qmlthread's Introduction

QmlThread

More powerful Thread module in QML.

old_code

新的想法

thread_in_qml

之前的设计思路是将 QJSEngine 移动到新线程,并为线程中的 QJSEngine 设计一套注册机制。现在看来拙劣至极。

直接将 QQmlEngine 移动到新的线程,qml 的类型注册与 QQmlEngine 实例化无关。然后 qml 的语法补全和智能提示又比 JavaScript 强太多了。所以决定使用 qml 作为线程处理的代码。

线程连接器:

    Thread {
        id: thread
        source: "./thread/thread_dir_size.qml"
        onMessageReceived: {
            console.log(message.toString())
        }
    }

接口设计可能参照 WebScoket 那样,就像主线程异步连接到了网络中一台功能强劲的电脑,将你的请求转化为运算,然后再将结果发送回主线程。

// thread_dir_size.qml 
// 约定文件名为小写开头,这样 QtCreator 的语法树模型就不会将主线程中的变量映射到这边。
import qyvlik.thread.runnable 0.1
import qyvlik.utility 0.1


QmlRunnable {
    id: runnable

    property var __: DirSize {
        id: dirsize
    }

    onMessageReceived: {
        console.time("dirsize")
        sendMessage(dirsize.dirSize(message));
        console.timeEnd("dirsize")
    }
}

讨论

qmlthread's People

Contributors

qyvlik avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.