zoukankan      html  css  js  c++  java
  • qml:基本知识记录

    1.  property信号处理函数;

         在qml中,通过property可以定义属性,这些属性自带信号处理函数,例如:

          property   string    szTitle: “hello world!"

         那么,   相应的就有了 onSzTitleChanged信号处理函数;

     2.  ListView的使用

    ListView{
                             200;        //宽高必须进行设置,不然显示不出来;
                            height: 300;
                            model: ListModel{
                                ListElement{test: "nihao"}
                                ListElement{test: "zhongguo"}
                                ListElement{test: "nihao"}
                                ListElement{test: "heelo"}
                                ListElement{test: "nihao"}
                            }
                            delegate:Text{ text: model.test;}      //delegate   单元素设置;
                }
    

     3.  alias 与 flickable联合使用;

    当使用alias对flickable进行联合,注意flickable的clip的设置,该设置默认是flase的,如果设置为true,那么就要设置width,height,不然内容不会自动进行弹动;

    4、资源文件的使用

      组件最好导入到资源文件中,这样在编译的时候可以讲组件编译成二进制,而且这样进行访问的时候也比较方便;

    5、Qt.platform.os的使用

      使用Qt.platform.os可以获取当前使用的系统,用来进行不同环境的配置。

           系统类别有:

    "android" - Android
    "blackberry" - BlackBerry OS
    "ios" - iOS
    "linux" - Linux
    "osx" - OS X
    "unix" - Other Unix-based OS
    "windows" - Windows
    "wince" - Windows CE
    "winrt" - Windows RT
    "winphone" - Windows Phone

     6、javascript 中 string中数字字符转换为int;

     譬如: "123world",从中提取出123;  使用函数parseInt();

    var  szStr = "123world"
    var  szTest = "100"
    parseInt(szStr)            //返回123;
    parseInt(szTest)          //返回100;
    

    7、QString格式化方式;

    QString格式化可以采用asprintf函数,该函数定义为static(即静态函数);

    [static] QString QString::asprintf(const char *cformat, ...)

    但是,新版本的qt不推荐这种方式,而推荐采用QTextStream or arg;

    arg:
     QString i;           // current file's number
      QString total;       // number of files to process
      QString fileName;    // current file's name
    
      QString status = QString("Processing file %1 of %2: %3")
                      .arg(i).arg(total).arg(fileName);
    QTextStream:
    
      QString result;
      QTextStream(&result) << "pi = " << 3.14;
      // result == "pi = 3.14"
    

    8、FocusScope

    FocusScope继承于item,提供焦点区域,可以用于复用性组件创建。

    9、Text and  TextField

    Text: 纯文本;

    TextField: 可供编辑的单行文本,通过设置readOnly为false,可以实现不可编辑,这时候仅能全选等操作而不能输入编辑。

    10、exe路径获取;

    头文件  #include <QCoreApplication>, 按照下面的方式获取exe文件的路径;

    QString szAppPath = QCoreApplication::applicationDirPath();
    

    11、QVariantList使用;

    QVariantList可以很方便实现C++与qml之间的数据交换,通过下面的方式实现双边转换:

    QVariantList  添加数据;
    
    例如: 将QString转换为QVariant;
    QString  szStr = "hello  world!";
    QVariantList   testList;
    testList.append(QVariant::fromValue(szStr));
    
    反过来,将QVariant转换为QString;
    
    QVariant  temp = testList[0];
    QString  szStr = temp.value<QString>();   注: value可以实现转换为自定义类型,比较方便,推荐使用;
    

      

     

    注: 该篇为扩展型博文,后续将逐步添加;

  • 相关阅读:
    Kylin 与 Spark SQL相比,有哪些差异和优势?
    apache kylin2.10在原生hadoop集群上安装
    ambari安装 QA
    mysql 5.7 学习
    Public key for ambari-server-2.4.2.0-136.x86_64.rpm is not installed 安装ambari报错总结
    python 练习
    centos 扩容
    Linux中Cache内存占用过高解决办法
    HyperLogLog
    星型模式、雪花模式和事实星座模式
  • 原文地址:https://www.cnblogs.com/yinwei-space/p/8705983.html
Copyright © 2011-2022 走看看