Qml 開發筆記

來源:互聯網
上載者:User

 

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()

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.