【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 语法错误表

相关推荐
xcyxiner7 小时前
DicomViewer (后台线程处理文件)4
qt
xcyxiner14 小时前
DicomViewer (添加模型类)3
qt
xcyxiner1 天前
DicomViewer (目录调整) 2
qt
xcyxiner1 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能3 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G3 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt
森G3 天前
77、线程池原理和实现------服务器源码解析----云视频服务项目
服务器·c++·qt
森G4 天前
71、打包发布---------打包发布
c++·qt
初圣魔门首席弟子4 天前
Node.js 详细介绍(知识库版)
windows·qt·node.js·知识库
C++ 老炮儿的技术栈4 天前
Qt工控实战:自研机器人TCP长连接客户端(粘包处理+心跳保活+自动重连完整源码解析)
qt·tcp/ip·机器人