当前位置:   article > 正文

QML first steps with QML_qthwaz

qthwaz

Creating a QML Document

     一个QML文件定义一个对象的层次结构,具有高度可读性和结构化的布局 。每个QML文件包括两部分:一个引入部分和一个对象声明部分。 用户界面中最常见的类型和功能由QtQuick引入。

Importing and Using the QtQuick Module

     为了使用QtQuick模块,一个QML文件需要将其引入,语法如下;

    import QtQuick 2.0

  Qt Quick提供的类型和功能同样可以在QML文件中使用 

Defining an Object Hierarchy (定义一个对象层次结构)

QML文件中的对象声明定义了将在可视化显示中的输出,QtQuick为所有的用户界面提供基本的构建筷

例如  显示图像,文本或者处理用户输入的对象  

  一个简单的对象声明可能是一个中间有文字的带颜色矩形


<span style="font-size:18px;">Rectangle {
    width: 200
    height: 100
    color: "red"

    Text {
        anchors.centerIn: parent
        text: "Hello, World!"
    }
}//根对象为Rectangle ,孩子对象为Text</span>
<strong><span style="font-size:24px;">Putting ir all together</span></strong>
<span style="font-size:18px;">将对象声明和引入放在一起
</span><pre name="code" class="plain"><span style="font-size:18px;">import QtQuick 2.1

Rectangle {
    width: 200
    height: 100
   

    Text {
        anchors.centerIn: parent//中间位置
        text: "Hello, World!"
     color: "red"
    }
}
将代码另存为helloworld.qml   在终端运行 qmlscene helloworld.aml
结果</span>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAACACAYAAABOUyafAAAABHNCSVQICAgIfAhkiAAAGVtJREFUeF7tXAt4lNWZfv+5zySTCwlCQiAhBBBFxaKAIKIIdSvYrnbbtXZbdVtru9subbd4wSpQK9Qb+yi9eRdrsWt1EasVpWpRVEBARKsoEAhyJ9fJJDOZ29n3zCWZTOaSaYv9yX+OzzyZ+f9zvv8773fe813Oj9opzmoB2UwayqvLUFJVCqfbAc1iil5WTSFgBAREKILOdj9a97egcW8jRERA48QtcvIWhxU1k2pQOKgAVosFZrMihxEWhZpjbwQcLhs54EJp1SDs3VSPgD8I7ZSCGlF37mgUlxfCZDIhFAojQvaophAwGgLSMVgsZgQCQXibO7Bz/U5Y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IPyOrmrihJ6j7gD9ss8oJA7fiJiZZ/m/UzK+beyiuOTHPXWm5lcs2DwJxYLptMrpGsyFwhSMQvjvFQfH6bOEV60pol/pN77Gc5Z6HUqqV+vOdHrhDnOliaqDnEcHSNKkvQJsj58kBiE6aEGM4RzS/cXb156Vh+952DeG+DNAATRkwW58P/nAp5TMPHffGfsDENP6ild+iCgCNIHkuN8oYm5x/4yvlbCqppqukdAEUT3JlIK/iMRSI1w/5G6qGcrBHSHgCKI7kyiFNITAoogerKG0kV3CCiC6M4kSiE9IaAIoidrKF10h4AiiO5MohTSEwKKIHqyhtJFdwgogujOJEohPSGgCKInayhddIeAIojuTKIU0hMCiiB6sobSRXcIKILoziRKIT0hoAiiJ2soXXSHgCKI7kyiFNITAoogerKG0kV3CCiC6M4kSiE9IaAIoidrKF10h4AiiO5MohTSEwKKIHqyhtJFdwgogujOJEohPSGgCKInayhddIeAIojuTKIU0hMCiiB6sobSRXcIKILoziRKIT0hoAiiJ2soXXSHgCKI7kyiFNITAoogerKG0kV3CCiC6M4kSiE9IaAIoidrKF10h4AiiO5MohTSEwKKIHqyhtJFdwgogujOJEohPSGgCKInayhddIeAIojuTKIU0hMCiiB6sobSRXcIKILoziRKIT0hoAiiJ2soXXSHgCKI7kyiFNITAoogerKG0kV3CCiC6M4kSiE9IaAIoidrKF10h8D/A4PNi4qPg+F5AAAAAElFTkSuQmCC" alt="" />
<span style="font-size:18px;">可知</span><pre name="code" class="plain"><pre name="code" class="plain"><span style="font-size:18px;"> anchors.centerIn: parent为居于父类的中间位置</span>

 
Creating and running QML projects
为了将qml文件图形化显示
,需要用Qt Creator来加载。选择File->new file or project ->applications->Qt Quick UI
输入完成代码后,通过Run运行
Creating QML Applications with Controls
对于创建一个新的应用程序,插入ApplicationWindow是一个好的起始点。
Building and Running an Example
打开QT在欢迎模式中,选择Example ,选择clock项目->复制到目录打开->运行
结果如图

如果出现../../Qt5.1.0/5.1.0/gcc_64/include/QtGui/qopengl.h:110:21: fatalerror: GL/gl.h: No such file or directory
在终端中执行
sudo apt-get install mesa-common-dev
编译出现如下错误提示:
/usr/bin/ld: cannot find -lGL
执行下面命令解决:
sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev

 


 


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/95263
推荐阅读
相关标签
  

闽ICP备14008679号