• QML出现error: Expected token `numeric literal'


    简单地在界面上画了两个Rectangle,运行出来,提示

    H:1_helloQtQuickmain0.qml:114: error: Expected token `numeric literal'

    最后发现:main.cpp中设置source时路径写错,应当有三个“/”,而不是两个: viewer.setSource(QUrl("qrc:///main.qml"));

    //main.cpp
    
    #include <QGuiApplication>
    #include <QQuickView>
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQuickView viewer;
        viewer.setResizeMode(QQuickView::SizeRootObjectToView);
        viewer.setSource(QUrl("qrc:///main.qml"));//正确的是三个
        viewer.show();
    
        return app.exec();
    }
    //main.qml
    
    import QtQuick 2.0
    import QtQuick.Window 2.12
    
    Rectangle {
        600;
       height: 400;
    
       Rectangle {
           id: rect1;
            200;
           height: 100;
           anchors.top: parent.top;
           anchors.topMargin: 20;
           anchors.left: parent.left;
           anchors.leftMargin: 20;
           gradient: Gradient {
               GradientStop {position: 0.0; color: "red"}
               GradientStop {position: 0.5; color: "blue"}
           }
       }
    
       Rectangle {
            id: rect2;
             200;
            height: 100;
            anchors.top: rect1.top;
            anchors.left: rect1.right;
            anchors.leftMargin: 20;
            rotation: 90;
            gradient: Gradient {
                GradientStop {position: 0.0; color: "black"}
                GradientStop {position: 0.5; color: "blue"}
            }
       }
    
    }


  • 相关阅读:
    mongodb(2)
    mongodb(1)
    分片集群
    副本集 集群
    java连接腾讯云上的redis
    maven打包
    生成ftp文件的目录树
    从ftp获取文件并生成压缩包
    android 连续点击退出程序
    Android之完美退出方法
  • 原文地址:https://www.cnblogs.com/BASE64/p/14469091.html
Copyright © 2020-2023  润新知