Unsolved Qt Application Crash
-
@Mr-.Wu Can you share the QML code (or better yet a minimal example) that can duplicate the crash?
-
Chat.qml
import QtQuick 2.4 import "qrc:/ui/javascript/watch_constants.js" as Constants import "qrc:/ui/javascript/watch_functions.js" as Functions ChatForm { id: chatForm Connections { target: btnChat onClicked: { Functions.getWindow("ChatWindow.qml").createChatListComponent() } } }
ChatForm.ui.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import "qrc:/ui/javascript/watch_constants.js" as Constants Item { width: 240 height: 240 property alias txtChat: txtChat property alias btnChat: btnChat Rectangle { id: rectangleChatsArea anchors.fill : parent color: Constants.LauncherBgColor Image { id: imageChatBg source: "qrc:/ui/images/launcher_bg.png" width: parent.width height: parent.height } Rectangle { height: 115 width: 115 anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter color: Constants.LauncherColor_Transparent Image { id: imageChatIoc source: "qrc:/ui/images/chat_ioc.png" } MouseArea { id: btnChat anchors.fill: parent } } Text { id: txtChat font.pixelSize: Constants.LauncherFontPixelSize font.family: Constants.LauncherFontFamily horizontalAlignment: Text.AlignHCenter anchors.bottom: parent.bottom anchors.bottomMargin: 24 anchors.horizontalCenter: parent.horizontalCenter color: Constants.LauncherTextColor width: 72 height: 24 } } }
RootWindow.qml
import QtQuick 2.7 import QtQuick.Window 2.2 import "qrc:/ui/javascript/watch_constants.js" as Constants import "qrc:/ui/javascript/watch_functions.js" as Functions Window { id: rootWindow x: 0 y: 0 width: 240 height: 240 flags: Qt.FramelessWindowHint // 显示区域 property alias rootRectangle: rootRectangle // 窗体组件(当前显示的组件) property var component: null // 点击事件 property alias rootMouseArea: rootMouseArea Rectangle { x: 0 y: 0 id: rootRectangle width: parent.width height: parent.height color: Constants.LauncherBgColor MouseArea { x: 0 y: 0 id: rootMouseArea anchors.fill: parent } } /************************************************** Function *******************************************************/ // 创建组件 function setupComponent(qml_file) { return setupComponentVisible(qml_file, true) } // 创建组件 function setupComponentVisible(qml_file, visible) { var parent = null if (component == null) parent = rootRectangle else parent = component var ret = Functions.dynamicCreateComponent(parent, qml_file, visible) if (ret != null) component = ret if(visible) component.visible = true return component } }
watch_functions.js
/* * Func: create component * Desc: dynamic create component * Para: parent , qml file , visible - true or false * Ret : component */ function dynamicCreateComponent(parent,qml_file,visible) { if(parent == null) { console.log("create component failed . the parent is null ."); return null; } if(qml_file == null) { console.log("create component failed . the qml file is null ."); return null; } var component = Qt.createComponent(qml_file); var qml_object = component.createObject(parent,{"x": 0, "y": 0}); if(qml_object !=null) qml_object.visible = visible; console.log("create component : " + qml_object + " , parent : " + qml_object.parent); return qml_object; } /* * Func: get window * Desc: get window * Para: window name * Ret : */ function getWindow(window_name) { if(window_name == null) { console.log("the window name is null . can't get it ."); return null; } var window = ui_management.existsWindow(window_name); if(window == null) { console.log("can't find the window named : " + window_name); return null; } return window.getQmlObject(); }
ChatWindow.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import "qrc:/ui" import "qrc:/ui/javascript/watch_constants.js" as Constants import "qrc:/ui/javascript/watch_functions.js" as Functions RootWindow { id: chatWindow visible: false width: 240 height: 240 signal createChatListComponent; Component.onCompleted: { createChatListComponent.connect(setupListView) console.log("Chat Window Completed") } Component.onDestruction: { createChatListComponent.disconnect(setupListView) console.log("Chat Window Destruction") } /************************************************** Function *******************************************************/ // 打开消息列表 function setupListView() { setupComponent(Constants.Compontent_ChatList) } }
-
When I double click quickly the mousearea named btnChat . The Application will be crash . This is a probabilistic event
-
@ambershark can you found the problem ?
-
@Mr-.Wu I'll play with it tomorrow and see if it crashes for me. I'll let you know.
Edit: Sorry didn't have time today, but will try to check it this week for sure. Busy time deadline wise for me right now.
-
@ambershark said in Qt Application Crash:
Sorry didn't have time today, but will try to check it this week for sure. Busy time deadline wise for me right now.
Okay. Thanks
-
@ambershark Did you do the test?
-
@Mr-.Wu Sorry I haven't yet. I have a tight deadline and had to write a ton of code this week. Worked some 12 hour days. I will try to test it soon though. Hopefully someone else can give it a shot too so you're not waiting on just me.
-
@ambershark Can you help us . We can't found the problem how to cause.
-
@Mr-.Wu Have you tried running the code with Qt 5.9? 5.9 is a long term release and if it's really a bug chances are good that it will be fixed with one of the bugfix releases.
-
@Mr-.Wu Ok finally had some time today to look at it. With the code you provided I can't get it to run as it's missing things.
So here's what we can do. Can you provide a simple example that duplicates the behavior? Does this happen with any mousearea or is it specific to one in your project? If you setup just a simple rect with a mousearea could you get it to crash? Does it crash while running in qmlscene or only when you run as an app?:
I tested with the following code:
import QtQuick 2.4 import QtQuick.Controls 2.0 Rectangle { width: 400 height: 400 color: "black" MouseArea { anchors.fill: parent onClicked: { parent.color = "red" } onDoubleClicked: { parent.color = "black" } } }
Everything was fine as fast as I could click. I just ran it with qmlscene though. Try that on your system and see if you can duplicate the crash if not, see what is different between how you use a MouseArea and what this simple one is doing. Then try to step it from a base MouseArea to your and find the point at which it breaks.
If you could give me a working project I could test yours and see if I can find the issue. I'm still learning QML myself though. I've been using Qt with QtWidgets for a very long time but am pretty new to QML as of last year. And since I haven't had a big project that needed it I just haven't had the exposure to the small problems it can produce yet. So I don't see anything obvious in your code.