Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt Application Crash
Forum Updated to NodeBB v4.3 + New Features

Qt Application Crash

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
12 Posts 3 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr .Wu
    wrote on last edited by
    #3

    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)
        }
    }
    
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mr .Wu
      wrote on last edited by
      #4

      When I double click quickly the mousearea named btnChat . The Application will be crash . This is a probabilistic event

      1 Reply Last reply
      0
      • A ambershark

        @Mr-.Wu Can you share the QML code (or better yet a minimal example) that can duplicate the crash?

        M Offline
        M Offline
        Mr .Wu
        wrote on last edited by
        #5

        @ambershark can you found the problem ?

        A 1 Reply Last reply
        0
        • M Mr .Wu

          @ambershark can you found the problem ?

          A Offline
          A Offline
          ambershark
          wrote on last edited by ambershark
          #6

          @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.

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          M 1 Reply Last reply
          1
          • A ambershark

            @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.

            M Offline
            M Offline
            Mr .Wu
            wrote on last edited by
            #7

            @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

            1 Reply Last reply
            0
            • A ambershark

              @Mr-.Wu Can you share the QML code (or better yet a minimal example) that can duplicate the crash?

              M Offline
              M Offline
              Mr .Wu
              wrote on last edited by
              #8

              @ambershark Did you do the test?

              A 1 Reply Last reply
              0
              • M Mr .Wu

                @ambershark Did you do the test?

                A Offline
                A Offline
                ambershark
                wrote on last edited by
                #9

                @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.

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                M 1 Reply Last reply
                0
                • A ambershark

                  @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.

                  M Offline
                  M Offline
                  Mr .Wu
                  wrote on last edited by
                  #10

                  @ambershark Can you help us . We can't found the problem how to cause.

                  S A 2 Replies Last reply
                  0
                  • M Mr .Wu

                    @ambershark Can you help us . We can't found the problem how to cause.

                    S Offline
                    S Offline
                    Schluchti
                    wrote on last edited by
                    #11

                    @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.

                    Want to read more about Qt?

                    https://gympulsr.com/blog/qt/

                    Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

                    1 Reply Last reply
                    0
                    • M Mr .Wu

                      @ambershark Can you help us . We can't found the problem how to cause.

                      A Offline
                      A Offline
                      ambershark
                      wrote on last edited by
                      #12

                      @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.

                      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved