QML出現error: Expected token `numeric literal'


簡單地在界面上畫了兩個Rectangle,運行出來,提示

H:\01_helloQtQuick\main0.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 {
   width: 600;
   height: 400;

   Rectangle {
       id: rect1;
       width: 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;
        width: 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"}
        }
   }

}

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM