qml(Qt Quick)做界面
來源 https://www.zhihu.com/question/24880681/answer/29324824
本人是Qt初學者,正在寫一個會計小軟件(Linux桌面版)。看了Qt的介紹,覺得用qml(Qt Quick)做界面非常機動快速,但是qml(Qt Quick)處理復雜的業務邏輯就有點力不從心了。
不知道能否用qml(Qt Quick)做界面,用C++(Qt)實現業務邏輯?如果可以,大概的思路是怎么樣?
不知道能否用qml(Qt Quick)做界面,用C++(Qt)實現業務邏輯?如果可以,大概的思路是怎么樣?
-----------------------------
題主你好,你說的這種思路是目前Digia主推的一種思路。(今年去參加Qt開發者大會的時候,幾乎一半的講座都會推薦這種用法。)
所以,如何結合QML和C++,官網上會有很多的例子和教程,希望你仔細看看。(另外,鑒於4.8時代的Qt Quick的問題(bug)還不少,所以建議使用最新版的Qt5.3+來做這樣的試驗。)
這是我隨手找到的:Introduction_to_Qt_Quick_for_Cpp_developers
Writing QML Extensions with C++
一個更詳盡的例子:
Qt Quick 之 QML 與 C++ 混合編程詳解
還有這個制作五子棋小游戲的教程,非常有意思。:http://quitcoding.com/download/Qt_Quick_Game_Programming_1_0.pdf
用的Qt Quick版本較老,但思路可以借鑒。
不謝。
-----------------------------
關於QML和C++的集成,參考文檔:http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
QtQuickControls以及QtQuickControls2的最新進展,
QtCS2015 QtQuickControls2
Background
QtQuick.Controls 1 has tons and tons of objects per control
Overview
QtQuick.Controls 2 has interaction logic in C++, greatly decreases object overhead and number of contexts
QtQuick.Controls 2 has visual items still in a (thin) QML layer
Styling, theming and customization
Native/platform styles currently out of scope
Would be in a separate (derived) imports?
Currently QtQuick.Controls 2 has a simple themable QML layer
Ongoing work adapting the palette concept from widgets (QTBUG-45839)
Parts of controls can be replaced with custom delegates
Status
Popup items vs. popup windows
Text selection handles via IM
No scaling (logical units?) thought of yet
Discussion
Accessibility in the QML layer? Needed as it's private from QtQuick
Some embedded users don't want accessibility. Seems "Short-sighted".
Continue with controls 1 until native/desktop gets brought into the controls 2 idea
As in done and maintained, but R&D on controls 2
大家可以參考:
=============== End