• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>


            Say hello to QtScript! 
            Posted by Kent on Friday, January 05, 2007 @ 09:25

            QtScript is a new module that will be introduced in the next minor release of Qt (4.3). It is a scripting environment that you embed in your C++ Qt application. While the release of Qt 4.3 is still a few months away, fortunately QtScript has just recently been integrated into the daily Qt snapshots, so you can start playing with it now. All you need to do is add

            QT += script

            to your .pro file, and

            #include

            in your source file(s), and you’re ready to rock.

            QtScript conforms to the ECMA-262 ECMAScript scripting language standard, the core language that’s the basis of JavaScript and Flash ActionScript (to name two well-known languages). The key ECMAScript extension provided by QtScript is the QObject extension; QtScript leverages the introspection capabilities of the Qt Meta-Object System to provide dynamic bindings of the signals and slots and properties of Qt objects (QObject and subclasses thereof).

            To give you an idea of what it looks like, here’s a small example showing how to register a widget in the scripting environment, and then manipulate it in script code:

            #include
            #include
            #include 
            int main(int argc, char *argv[])
            {
            QApplication app(argc, argv);
            QPushButton button;
            
            QScriptEngine engine;
            QScriptValue scriptButton = engine.scriptValueFromQObject(&button);
            engine.globalObject().setProperty(”button”, scriptButton);
            engine.evaluate(”button.text = ‘Hello World!’”);
            engine.evaluate(”button.styleSheet = ‘font-style: italic’”);
            engine.evaluate(”button.show()”);
            
            return app.exec();
            }

            In script code, you can connect to signals of a Qt object. The target of the connection can either be a Qt slot, or a script function. Example of the latter:

            function onButtonClicked(checked) {
            print ("button was checked:", checked);
            print ("button text:", this.text);
            }
            button.clicked.connect(onButtonClicked);

            As you can see, the sender() of the signal is available as the this object in the script function. You can also use array-style member access:

            button['toggled(bool)'].connect(app.quit);

            You can disconnect from the signal again like so:

            button.clicked.disconnect(onButtonClicked);

            If you’re never going to explicitly disconnect from the signal again, the target function can be anonymous:

            button.clicked.connect(
            function (checked) {
            print ("button was checked:", checked);
            print ("button text:", this.text);
            }
            }

            Child objects are accessible as members too, so long as the child has its objectName set. A natural application of this feature is when building user interfaces at runtime: Use QUiLoader to build the form, then manipulate the form from script code:

            form.buttonBox.accepted.connect(/* some function */)
            form.buttonBox.rejected.connect(/* some function */)
            form.userNameEdit.text = "Ned Flanders";
            form.exec();

            There’s more interesting stuff you can do, such as registering your own functions for value conversion (marshalling), binding C++ functions (not just slots), and making slots “script-aware” (using a class called QScriptable). See the QtScript docs in the snapshots for more information.

            And finally, some quick questions and answers:

            Q: What about QSA?
            A: For those of you familiar with QSA (Qt Script for Applications): The new QtScript module bears no relation to QSA. The API is new and the implementation is new. QSA will reach the end of its lifetime in 2008. We’re not touting QtScript as a “QSA replacement” per se, but QtScript clearly offers a lot of the same functionality as QSA, and will naturally offer even more in the future. Just don’t expect to be able to port your existing QSA projects to QtScript in under an hour; as already stated, QSA and QtScript are similar in concept, but very different in practice.

            Q: What about performance?
            A: QtScript offers far better performance than, say, QSA (by a couple of orders of magnitude). The performance is comparable to SpiderMonkey in most areas.

            Q: What about bindings for the rest of Qt?
            A: The emphasis is not on bindings for the 4.3 release, but rather on the core scripting environment; e.g. interpreter, ECMAScript compliance, QObject bindings. We offer an API you can use for writing your own bindings, in case the QObject bindings are not sufficient. Don’t expect to be able to write entire applications in only QtScript, at least not with the first release.

            Well, have fun and let us know what you think. Remember, there’s still time for us to take your thoughts into account before the first official QtScript release.

            posted on 2007-10-07 00:17 清源游民 閱讀(3280) 評(píng)論(3)  編輯 收藏 引用 所屬分類: Qt

            FeedBack:
            # re: Say hello to QtScript!(轉(zhuǎn))
            2007-10-07 06:57 | Minidx全文檢索
            唉……  回復(fù)  更多評(píng)論
              
            # re: Say hello to QtScript!(轉(zhuǎn))[未登錄]
            2007-11-20 14:04 | fred
            engine.scriptValueFromQObject(&button);

            QScriptEngine 里沒有scriptValueFromQObject這個(gè)函數(shù)啊


            不知道大俠用的是什么版本的  回復(fù)  更多評(píng)論
              
            # re: Say hello to QtScript!(轉(zhuǎn))[未登錄]
            2007-11-20 14:58 | fred
            QPushButton button;

            QScriptEngine engine;
            QScriptValue scriptButton = engine.newQObject( &button);
            engine.globalObject().setProperty("button", scriptButton);
            engine.evaluate("button.text = 'Hello World!'");
            engine.evaluate("button.styleSheet = 'font-style: italic'");
            engine.evaluate("button.show()");  回復(fù)  更多評(píng)論
              
            <2007年10月>
            30123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            留言簿(35)

            隨筆分類(78)

            隨筆檔案(74)

            文章檔案(5)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            日本五月天婷久久网站| 69久久夜色精品国产69| 精品久久久久久无码国产| 久久精品亚洲福利| 久久综合给合久久狠狠狠97色69| 国产美女久久久| 国产aⅴ激情无码久久| 91麻豆精品国产91久久久久久| 亚洲精品无码久久毛片| 国产成人无码久久久精品一| 国产成人精品久久综合| 国产精品对白刺激久久久| 人人狠狠综合久久亚洲| AV色综合久久天堂AV色综合在| 久久亚洲精品无码播放| 狠狠色丁香婷婷久久综合不卡| 久久天天躁狠狠躁夜夜2020一| 99久久精品这里只有精品| 亚洲精品乱码久久久久久久久久久久| 精品国产福利久久久| 亚洲人成网亚洲欧洲无码久久 | 久久久精品一区二区三区| 亚洲精品NV久久久久久久久久| 久久精品国产影库免费看| 浪潮AV色综合久久天堂| 久久狠狠爱亚洲综合影院| 亚洲精品无码专区久久同性男| 日本免费久久久久久久网站| 国产成人精品免费久久久久| 久久亚洲精品成人AV| 午夜欧美精品久久久久久久| 久久精品国产亚洲av麻豆蜜芽| 久久久这里有精品中文字幕| 国产女人aaa级久久久级| 久久成人永久免费播放| 久久亚洲精品无码观看不卡| 久久久久亚洲av成人无码电影| 久久人人爽人人爽人人片AV麻豆| 久久久久99精品成人片牛牛影视| 青青青青久久精品国产h| 免费观看久久精彩视频|