Android QML文本有奇怪的行为?文本未出现并导致应用程序崩溃

Android QML文本有奇怪的行为?文本未出现并导致应用程序崩溃,android,qt,qml,qtquick2,Android,Qt,Qml,Qtquick2,我在QML中遇到了一个奇怪的行为Text。我承认这可能是我的错,但我不知道怎么回事。我正在创建一个类似android Gmail/Inbox应用程序的滑动菜单。当回答时,我发现最好的方法是创建我自己的按钮,这样我有以下代码: 菜单按钮: Item { id: root property string text: "" signal clicked() width: 100 height: 62 Rectangle { anch

我在QML中遇到了一个奇怪的行为
Text
。我承认这可能是我的错,但我不知道怎么回事。我正在创建一个类似android Gmail/Inbox应用程序的滑动菜单。当回答时,我发现最好的方法是创建我自己的按钮,这样我有以下代码:

菜单按钮

Item {
    id: root

    property string text: ""
    signal clicked()

    width: 100
    height: 62

    Rectangle {
        anchors.fill: parent
    }

    Text {
        anchors.centerIn: parent
        text: parent.text
    }

    MouseArea {
        anchors.fill: parent

        onClicked: {
            parent.clicked();
        }
    }
}
Rectangle {
    id: root
    height: 50
    color: "#4285f4"
    border.width: 0
    border.color: "#00000000"

    property SliderMenu slider

    ToolButton {
        id: slideButton
        x: 5
        y: 7
        width: 36
        height: 36
        iconSource: "../../resources/MainMenu/slide_menu_icon.png"
        onClicked: {
            slider.showMenu();
        }
    }
}
我的
幻灯片菜单如下所示:

Item {
    id: root

    function showMenu(startX, duration) {
        //Start animation to show menu.
    }

    function hideMenu(startX, duration) {
        //Start animation to hide menu.
    }

    clip: true
    visible: false
    Item {
        id: menu

        //shadow adds 1 pixel
        property int maxX: -1
        property int minX: -width - 1
        //Arbitrary number for what is considered fast
        property int fastSwipe: 200

        y: -1
        width: 250
        height: parent.height + 1
        visible: false

        Rectangle {
            id: rectMenu
            anchors.fill: parent
            color: "#ececec"
            visible: false
        }

        DropShadow {
            id: menuShadow
            anchors.fill: rectMenu
            horizontalOffset: 1
            verticalOffset: 0
            radius: 4
            samples: radius * 2
            spread: 0
            color: "#80000000"
            source: rectMenu
            transparentBorder: true
        }

        MenuButton {
            x: 10
            y: 20
            text: "Text"
            onClicked: {
                console.log("I'm here!");
            }
        }

        SwipeArea {
            //Swipe area code
        }

        NumberAnimation {
            //Code of the sliding in animation
        }

        NumberAnimation {
            //Code for the sliding out animation
        }
    }
}
通过单击
顶部菜单
按钮
打开滑块:

Item {
    id: root

    property string text: ""
    signal clicked()

    width: 100
    height: 62

    Rectangle {
        anchors.fill: parent
    }

    Text {
        anchors.centerIn: parent
        text: parent.text
    }

    MouseArea {
        anchors.fill: parent

        onClicked: {
            parent.clicked();
        }
    }
}
Rectangle {
    id: root
    height: 50
    color: "#4285f4"
    border.width: 0
    border.color: "#00000000"

    property SliderMenu slider

    ToolButton {
        id: slideButton
        x: 5
        y: 7
        width: 36
        height: 36
        iconSource: "../../resources/MainMenu/slide_menu_icon.png"
        onClicked: {
            slider.showMenu();
        }
    }
}
在主屏幕上是这样的:

Item {
    anchors.fill: parent
    z: 1

    TopMenu {
        x: 0
        y: 0
        width: parent.width
        height: 50
        slider: sliderMenu
    }

    SliderMenu {
        id: sliderMenu
        x: 0
        y: 0
        anchors.fill: parent
    }
}
当我按下
TopMenu的按钮
将菜单滑入视图时,90%的时间(并非总是)应用程序会崩溃。如果我从
菜单按钮中删除
文本
,它将不再崩溃。此外,我还尝试在
幻灯片上的任何位置添加
文本
,而不是
菜单按钮
,结果相同

我还尝试使
菜单始终可见(这样我就不必按
按钮才能显示),应用程序不再崩溃,但90%的时间
文本不在那里!
它似乎只有在最初隐藏时才会崩溃,如果一开始没有崩溃,它也不会崩溃,即使我隐藏菜单并再次打开

崩溃导致调试时出现分段错误

有人知道这可能是什么吗

谢谢你抽出时间

编辑:我在windows上运行这个,因为它测试速度更快,而且我希望它也在windows上运行。我刚刚在安卓系统内部进行了测试,它似乎没有崩溃。但每次打开或关闭菜单时,控制台上都会出现此错误:

Drawable.qml:70 ((null)): file:///data/data/org.qtproject.example.OSC_Client/qt-reserved-files/qml/QtQuick/Controls/Styles/Android/drawables/Drawable.qml:70: TypeError: 
Cannot read property 'padding' of undefined

W/libOSC-Client.so(25977): file:///data/data/org.qtproject.example.OSC_Client/qt-reserved-files/qml/QtQuick/Controls/Styles/Android/drawables/AnimationDrawable.qml:53 ((null)): file:///data/data/org.qtproject.example.OSC_Client/qt-reserved-files/qml/QtQuick/Controls/Styles/Android/drawables/AnimationDrawable.qml:53:28:
Unable to assign [undefined] to bool
EDIT2:我刚刚设法以一种更简单的方式复制了这个bug。这似乎与矩形上的DropShadow有关。下面是更简单的代码。当我运行它时,90%的时间文本不会出现。在windows上的MinGW和MSVC2012上测试

import QtQuick 2.4
import QtQuick.Controls 1.3

import QtGraphicalEffects 1.0

ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480
    visible: true

    Button {
        x: 0
        y: 350
        text: "Show Rectangle"
        onClicked: rect.visible = true;
    }

    Item {
        id: rect
        x: -1
        y: -1
        width: 250
        height: 300
        visible: false

        Rectangle {
            id: rectMenu
            anchors.fill: parent
            color: "#ececec"
            visible: false

        }

        DropShadow {
            id: menuShadow
            anchors.fill: rectMenu
            horizontalOffset: 1
            verticalOffset: 0
            radius: 4
            samples: radius * 2
            spread: 0
            color: "#80000000"
            source: rectMenu
            transparentBorder: true
        }

        Text {
            anchors.centerIn: parent
            text: "Text"

        }
    }
}
如果我删除
DropShadow
,它将正常显示文本

qt.qpa.gl日志:

qt.qpa.gl: createPlatformOpenGLContext QSurfaceFormat(version 2.0, options QFlags(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 1, profile  0)
qt.qpa.gl: Qt: Using WGL and OpenGL from "opengl32.dll"
qt.qpa.gl: create OpenGL: "Intel","Intel(R) HD Graphics 3000" default ContextFormat: v3.1 profile: 0 options: QFlags(0x4),SampleBuffers, Extension-API present
Extensions: 116
qt.qpa.gl: "choosePixelFormat  Attributes:  0x2003 , 0x2027 , 0x2010 , 0x1 , 0x2001 , 0x1 , 0x2014 , 0x18 , 0x2011 , 0x1 , 0x2022 , 0x18 , 0x2013 , 0x202b , 0x201b , 0x8 , 0x2023 , 0x8 , 0x2041 , 0x0 , 
    obtained px # 4  of  1 
     PIXELFORMATDESCRIPTOR dwFlags=0x8225 PFD_DRAW_TO_WINDOW PFD_SUPPORT_OPENGL PFD_SUPPORT_COMPOSITION PFD_DOUBLEBUFFER iPixelType=0 cColorBits=32 cRedBits=8 cRedShift=16 cGreenBits=8 cGreenShift=8 cBlueBits=8 cBlueShift=0 cDepthBits=24 cStencilBits=8 iLayerType=0 cAlphaBits=8 cAlphaShift=24 cAccumBits=64 cAccumRedBits=16 cAccumGreenBits=16 cAccumBlueBits=16 cAccumAlphaBits=16"
qt.qpa.gl: createContext Creating context version 2 . 0 3 attributes
qt.qpa.gl: QWindowsGLContext 0x281246a0 ARB  requested:  QSurfaceFormat(version 2.0, options QFlags(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 1, profile  0) 
    obtained # 4 ARB QSurfaceFormat(version 3.1, options QFlags(0x4), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior 2, swapInterval 1, profile  0) 
     PIXELFORMATDESCRIPTOR dwFlags=0x8225 PFD_DRAW_TO_WINDOW PFD_SUPPORT_OPENGL PFD_SUPPORT_COMPOSITION PFD_DOUBLEBUFFER iPixelType=0 cColorBits=32 cRedBits=8 cRedShift=16 cGreenBits=8 cGreenShift=8 cBlueBits=8 cBlueShift=0 cDepthBits=24 cStencilBits=8 iLayerType=0 cAlphaBits=8 cAlphaShift=24 cAccumBits=64 cAccumRedBits=16 cAccumGreenBits=16 cAccumBlueBits=16 cAccumAlphaBits=16 swap interval: 1
    default: ContextFormat: v3.1 profile: 0 options: QFlags(0x4)
    HGLRC=0x20000

不是没有堆栈跟踪。从您展示的QML来看,似乎没有任何原因导致SEGFULT。通常当普通QML代码中出现segfault时,这是Qt中的一个bug。我刚刚发现这与矩形上的DropShadow有关。我已经在这个问题上添加了一个简单的代码,它创建了这个bug。你认为这是Qt中的一个bug吗?顺便说一句,我正在windows上使用MinGW。如何从Qt Creator获取堆栈跟踪?您使用的是哪个Qt版本?您需要启用QML调试,然后调试应用程序(F5)以获得堆栈跟踪。我这样做了,但当它崩溃时,堆栈跟踪基本上是:0级,函数级别1,函数??是您刚刚更新了整个main.QML的QML吗?如果没有,请发布整个内容,因为它不会让我在装有Qt5.4.0(MSVC2010)的Windows上崩溃。当它崩溃时会发生什么?有断言吗?没有堆栈跟踪。从您展示的QML来看,似乎没有任何原因导致SEGFULT。通常当普通QML代码中出现segfault时,这是Qt中的一个bug。我刚刚发现这与矩形上的DropShadow有关。我已经在这个问题上添加了一个简单的代码,它创建了这个bug。你认为这是Qt中的一个bug吗?顺便说一句,我正在windows上使用MinGW。如何从Qt Creator获取堆栈跟踪?您使用的是哪个Qt版本?您需要启用QML调试,然后调试应用程序(F5)以获得堆栈跟踪。我这样做了,但当它崩溃时,堆栈跟踪基本上是:0级,函数级别1,函数??是您刚刚更新了整个main.QML的QML吗?如果没有,请发布整个内容,因为它不会让我在装有Qt5.4.0(MSVC2010)的Windows上崩溃。当它崩溃时会发生什么?有断言吗?没有堆栈跟踪。从您展示的QML来看,似乎没有任何原因导致SEGFULT。通常当普通QML代码中出现segfault时,这是Qt中的一个bug。我刚刚发现这与矩形上的DropShadow有关。我已经在这个问题上添加了一个简单的代码,它创建了这个bug。你认为这是Qt中的一个bug吗?顺便说一句,我正在windows上使用MinGW。如何从Qt Creator获取堆栈跟踪?您使用的是哪个Qt版本?您需要启用QML调试,然后调试应用程序(F5)以获得堆栈跟踪。我这样做了,但当它崩溃时,堆栈跟踪基本上是:0级,函数级别1,函数??是您刚刚更新了整个main.QML的QML吗?如果没有,请发布整个内容,因为它不会让我在装有Qt5.4.0(MSVC2010)的Windows上崩溃。当它崩溃时会发生什么?有断言吗?