Qml 開發筆記

 

1. 編譯中出現“The process could not be started!”錯誤

 

在Qml Viewer中添加qml Exe路徑“C:/Qt/4.7.0/bin/qmlviewer.exe”

Main QML File可以選擇 編譯運行的qml文件

 

2. 

在Model的append方法中每一個屬性間需要“,” 分割,如果沒有的話運行會報,Unable to assign [undefined] to QUrl source 錯誤

 

3.

如果將model單獨寫出一qml,則ListView中的model要使用model的qml文件名並加"{}",否則如果都寫在main中,則ListView中的model使用model的id。

 

4. 如何在QML中直接調用Qt中類的方法。

http://www.thisisqt.com/forum/viewthread.php?tid=346

http://www.thisisqt.com/?action-viewnews-itemid-12

http://wiki.forum.nokia.com/index.php/%E5%9C%A8C%2B%2B%E7%A8%8B%E5%BA%8F%E4%B8%AD%E4%BD%BF%E7%94%A8QML

 

 

爲了能讓在QML中可以直接調用某個方法,這個方法需要滿足以下兩個條件其中一個:

1.這個方法是是一個公開的槽,即聲明在public slots訪問區域中的方法。但有個缺點,槽沒有返回值,

如果你需要使用返回值,請使用條件2。

2.方法的聲明前需要帶Q_INVOKABLE宏.

 

在main函數中我們調用setContextProperty將StringHelper設爲QDeclarativeView中根元素上下文的一個屬性。

這樣ui.qml中的根元素rec就可以將StringHelper視爲其子元素。

 

 

5. QML WorkerScript Element

The WorkerScript element enables the use of threads in QML

 

source : url

Signals : onMessage

Methods : sendMessage

 

Detailed Description

Use WorkerScript to run operations in a new thread. This is useful for running operations in the background so that the main GUI thread is not blocked.

Messages can be passed between the new thread and the parent thread using sendMessage() and the onMessage() handler.

 

 

6.

property color buttonColor: "lightblue"

自定義的屬性用property type name:值 語句來聲明。

 

 

7. QML之可視化元素

1、Item

所有的QML可視化元素都繼承自Item。Item沒有可視化界面,但是它定義了可視化元素的所有屬性。

//記住要爲Item指定width和height不然運行看不到窗體 

 

 

 

 

8. 下面是介紹QML元素。元素作爲QML編程的最基本單元。主要分爲以下幾大類:

Basic Visual Items(基礎可視單元)

Basic Interaction Items(基礎交互單元)

States(狀態)

Animation and Transitions(動畫和過渡)

Working with Data(數據操作)

Views(視圖)

Positioners(位置)

Utility(通用)

Transforms(變換)

Effects(效果)

 

 

9. Qml中的定時器是Timer對象

     Timer {

         interval: 100; running: true; repeat: true;

         onTriggered: clock.timeChanged()

     }

clock.timeChanged調用的是Id爲clock的組件中的json函數 timeChanged()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章