什么是Qt Quick的编译器做什么呢?我的理解是它将 QML/JS“编译”为 C++ 并将其集成到最终的二进制文件/可执行文件中。因此,在运行时没有 JIT 编译或任何其他与 JS 相关的东西。
然而,我在某处看到一篇文章声称它不是这样的,实际上它只是将 QML/JS“捆绑”到最终的二进制/可执行文件中,但在运行时仍然存在一些与 QML/JS 相关的开销。
在文档页面上有这样的解释:
.qml 文件以及随附的 .js 文件可以转换为 中间 C++ 源代码。使用传统编译器编译后,代码会链接到应用程序二进制文件中。
这个“中间C++源代码”是什么?为什么不只是“C++ 源代码”?这让我很困惑,但最后一条语句有点承诺,是的,它是一个 C++ 代码,在用 C++ 编译器编译它之后,你将拥有一个二进制/可执行文件,在运行时无需任何额外的编译/解释。
真的是这样吗?
我正在尝试在 Python 脚本中添加类型注释/提示以运行mypy检查。我有一个pandas.DataFrame
对象,我像这样迭代它:
someTable: pandas.DataFrame = pandas.DataFrame()
# ...
# adding some data to someTable
# ...
for index, row in someTable.iterrows():
#reveal_type(index)
print(type(index))
print(index + 1)
Run Code Online (Sandbox Code Playgroud)
如果我运行这个脚本,我会得到以下结果:
$ python ./some.py
<class 'int'>
2
<class 'int'>
3
Run Code Online (Sandbox Code Playgroud)
如果我用 检查它mypy
,那么它会报告错误:
$ mypy ./some.py
some.py:32: note: Revealed type is "Union[typing.Hashable, None]"
some.py:34: error: Unsupported operand types for + ("Hashable" and "int")
some.py:34: error: Unsupported operand types for + ("None" and "int")
some.py:34: note: Left operand …
Run Code Online (Sandbox Code Playgroud) 我想div
只在用户登录时在视图中显示一些内容.
这就是我试图这样做的方式:
@{
if (Request.IsAuthenticated)
// if (User.Identity.IsAuthenticated)
{
<div>
Some content only for logged in users.
</div>
}
}
Run Code Online (Sandbox Code Playgroud)
但是,Request.IsAuthenticated
(和User.Identity.IsAuthenticated
)是始终 true
,即使是在最开始,之后我开始从Visual Studio的网站.显然,它让我当用户登录Windows(因为User.Identity.Name
返回我的Windows登录),但我需要它来检查用户是否通过网站进行了身份验证FormsAuthentication
.
那是我的web.config:
<authentication mode="Forms">
<forms loginUrl="/Account/Login" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
如何检查用户是否已通过登录FormsAuthentication
?
Startup.cs
:
// ...
app.Use(async (context, next) =>
{
context.Response.Headers.Add("X-Frame-Options", "DENY");
context.Response.Headers.Add("X-Content-Type-Options", "nosniff");
context.Response.Headers.Add("Server", "ololo");
await next();
});
if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); }
else { app.UseExceptionHandler("/Home/Error"); }
app.UseStaticFiles();
app.UseAuthentication();
// ...
Run Code Online (Sandbox Code Playgroud)
当一切正常时,我会按预期得到以下标头:
HTTP/1.1 200 OK
Connection: close
Date: Mon, 30 Jul 2018 18:39:33 GMT
Content-Type: text/html; charset=utf-8
Server: ololo
Transfer-Encoding: chunked
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Run Code Online (Sandbox Code Playgroud)
因此Server
,X-Frame-Options
和X-Content-Type-Options
标头被覆盖。
但是如果我的代码中有未处理的异常,那么我会得到这些标头:
HTTP/1.1 500 Internal Server Error
Connection: close
Date: Mon, 30 Jul 2018 18:35:49 GMT
Content-Type: text/html; charset=utf-8 …
Run Code Online (Sandbox Code Playgroud) asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
compilation ×1
mypy ×1
pandas ×1
python ×1
qml ×1
qt ×1