QML--学习第一篇

来源:互联网 发布:mac玩梦幻西游快捷键 编辑:程序博客网 时间:2024/04/28 02:52

感觉Qt creator的QML例子太复杂,不容易学习,特意选择了一些搜集的例子学习。希望自己学习的过程给大家带来帮助。

 QML之第一篇:hello world


main.cpp

[cpp] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. #include <QtWidgets/qapplication.h>  
  2. #include <qtdeclarative/QDeclarativeview.h>  
  3. int main(int argc, char *argv[])  
  4. {  
  5.     QApplication a(argc, argv);  
  6.     QDeclarativeView *m_qmlView = new QDeclarativeView();   
  7.     m_qmlView->setSource(QUrl::fromLocalFile("source.qml"));    
  8.     m_qmlView->show();  
  9.     return a.exec();  
  10. }  

source.qml

[cpp] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. import QtQuick 1.0  
  2.   
  3. Rectangle {                     //root object  
  4.     id: page                    //Rectangle property, We give it an id to be able to refer to it later.  
  5.     width: 320; height: 480  
  6.     color: "lightgray"  
  7.     Text {  
  8.         id: helloText  
  9.         text: "Hello world!"  
  10.         y: 30  
  11.         anchors.horizontalCenter: page.horizontalCenter  
  12.         font.pointSize: 24; font.bold: true  
  13.     }  
  14. }  

库文件:Qt5Declaratived.lib    Qt5Guid.lib   Qt5Widgetsd.lib    Qt5Cored.lib

环境:    VS2010 + win7-64位 + Qt5

显示效果:



FROM: http://blog.csdn.net/qyee16/article/details/17271559

1 0
原创粉丝点击