我使用基于ArchLinux 64bit.
的{{3}} Qt Opensource 5.10.0以及QtQuick.Controls 1.4
所需的Qt Creator 4.5.0州:
import QtQuick 2.10
import QtQuick.Controls 1.4
ApplicationWindow
{
width: 640
height: 480
visible: true
toolBar: ToolBar
{
} // ToolBar
} // ApplicationWindow
编译并运行正常。现在,我想将docs for ApplicationWindow添加到较高ApplicationWindow
,但QtQuickControls 1.4
无法识别它,因为它也在SwipeView中说明并且需要import QtQuick.Controls 2.3
,所以如果我在import QtQuick.Controls 1.4
中提出了main.qml
:
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
如果使用import 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
的成员/属性{{3在第二种情况下?
答案 0 :(得分:1)
好的,这种二元性源于这样一个事实,即有2 ApplicationWindow
,一个来自import QtQuick.Controls 1.4
,第二个来自import QtQuick.Controls 2.3
。新的没有toolBar
所以你得到了错误。
如果你仍然想使用旧的,你可以使用别名如下:
import QtQuick.Controls 1.4 as Old
Old.ApplicationWindow {
toolBar: ToolBar
{
}
}
或者您应该在新版本中使用ApplicationWindow.header:
ApplicationWindow {
header: TabBar {
// ...
}
}
我不知道为什么Qt将名称从toolBar
更改为header
。对我来说,它看起来不合逻辑。