Qml 由于导入错误,带工具栏的ApplicationWindow无法保存SwipeView
我使用的基于Qml 由于导入错误,带工具栏的ApplicationWindow无法保存SwipeView,qml,qtquickcontrols,qtquickcontrols2,Qml,Qtquickcontrols,Qtquickcontrols2,我使用的基于ArchLinux 64位。及其所需的状态QtQuick.Controls 1.4: import QtQuick 2.10 import QtQuick.Controls 1.4 ApplicationWindow { width: 640 height: 480 visible: true toolBar: ToolBar { } // ToolBar } // ApplicationWindow 它编译并运行正常。
ArchLinux 64位。
及其所需的状态QtQuick.Controls 1.4
:
import QtQuick 2.10
import QtQuick.Controls 1.4
ApplicationWindow
{
width: 640
height: 480
visible: true
toolBar: ToolBar
{
} // ToolBar
} // ApplicationWindow
它编译并运行正常。现在,我想添加到upperApplicationWindow
,但是QtQuickControls 1.4
无法识别它,因为它也在中声明并要求导入QtQuick.Controls 2.3,因此如果我让在main.qml
中导入QtQuick.Controls 1.4
:
import QtQuick 2.10
import QtQuick.Controls 1.4
ApplicationWindow
{
width: 640
height: 480
visible: true
toolBar: ToolBar
{
} // ToolBar
SwipeView
{
} // SwipeView
} // ApplicationWindow
我得到一个错误:
Starting /mnt/projects/build-test12-Desktop_Qt_5_10_0_GCC_64bit-Debug/test12...
QML debugging is enabled. Only use this in a safe environment.
QQmlApplicationEngine failed to load component
qrc:/main.qml:15 SwipeView is not a type
/mnt/projects/build-test12-Desktop_Qt_5_10_0_GCC_64bit-Debug/test12 exited with code 255
如果使用导入QtQuick.Controls 2.3
:
import QtQuick 2.10
import QtQuick.Controls 2.3
ApplicationWindow
{
width: 640
height: 480
visible: true
toolBar: ToolBar
{
} // ToolBar
SwipeView
{
} // SwipeView
} // ApplicationWindow
我发现以下错误:
Starting /mnt/projects/build-test12-Desktop_Qt_5_10_0_GCC_64bit-Debug/test12...
QML debugging is enabled. Only use this in a safe environment.
QQmlApplicationEngine failed to load component
qrc:/main.qml:11 Cannot assign to non-existent property "toolBar"
/mnt/projects/build-test12-Desktop_Qt_5_10_0_GCC_64bit-Debug/test12 exited with code 255
现在,如果我同时包含两个导入:
import QtQuick 2.10
import QtQuick.Controls 1.4
import QtQuick.Controls 2.3
ApplicationWindow
{
width: 640
height: 480
visible: true
toolBar: ToolBar
{
} // ToolBar
SwipeView
{
} // SwipeView
} // ApplicationWindow
我仍然得到:
Starting /mnt/projects/build-test12-Desktop_Qt_5_10_0_GCC_64bit-Debug/test12...
QML debugging is enabled. Only use this in a safe environment.
QQmlApplicationEngine failed to load component
qrc:/main.qml:12 Cannot assign to non-existent property "toolBar"
/mnt/projects/build-test12-Desktop_Qt_5_10_0_GCC_64bit-Debug/test12 exited with code 255
如第二种情况。
第一个错误是合乎逻辑的,因为在版本
1.4
中没有SwipeView
,但是,为什么QtQuick.Controls 2.3
在第二种情况下无法识别ApplicationWindow
的成员/属性?好的,这种二元性是由于存在两个ApplicationWindow
这一事实而产生的,一个来自import QtQuick.Controls 1.4
,第二个来自import QtQuick.Controls 2.3
。新的工具没有工具栏
,因此您会得到错误
如果仍要使用旧版本,可以使用别名,如下所示:
import QtQuick.Controls 1.4 as Old
Old.ApplicationWindow {
toolBar: ToolBar
{
}
}
或者,您应该在新版本中使用:
ApplicationWindow {
header: TabBar {
// ...
}
}
我不知道为什么Qt将名称从
工具栏
更改为标题
。对我来说,这似乎不合逻辑。为什么不同时使用这两种导入<代码>导入QtQuick。控件2.3导入QtQuick。控件1.4。根据ApplicationWindow
requiresimport QtQuick.Controls 1.4
如果我同时使用这两种控件,我仍然会得到工具栏
错误,第二种情况。您能否用相关代码和使用代码得到的错误更新您的问题?这将更清晰、更容易运行。@folibis我已经在问题中提供了一个简单的最小示例,但有错误。是的,您说您同时使用了两个导入,但我看到两段代码,每个都使用自己的导入。如果我想运行代码以获得与您相同的错误,我必须自己编写代码,而不是复制您的代码。哇,它很管用!然而,您可能知道,哪个文件ApplicationWindow
用于将来的检查吗?“我不知道为什么Qt将名称从工具栏更改为标题。对我来说,它看起来不符合逻辑。”-我会假设,因为不仅仅是桌面应用程序使用ApplicationWindow
,所以更通用的名称更好。另外还有页脚
,所以有一个匹配的页眉
是有意义的。是的@Mitch,从这个意义上说,你可能是对的。值得更广泛地思考=)