【QML】警告Name is declared more than once

1. 问题:

qml函数中的不同块中定义同名变量,报警:Name is declared more than once

举例:

c 复制代码
function test(a){
	if(a === "1"){
		var re = 1;
		console.log(re);
	}else{
		var re = 2;	//这里会报警:Name is declared more than once
		console.log(re);
	}
}

2. 原因:

  • qml与C++不同。
  • qml在函数中声明的变量在函数中的任何地方都是可见的,即使在嵌套块或语句条件中声明也是如此。重新声明变量没有效果。

参考:

Qt:QML:JavaScript 和QML 语法错误表

相关推荐
用户8055336980318 小时前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner19 小时前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz6 天前
QML Hello World 入门示例
qt
xcyxiner9 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner9 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner10 天前
DicomViewer (添加模型类)3
qt
xcyxiner11 天前
DicomViewer (目录调整) 2
qt
xcyxiner11 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能13 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G13 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt