Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Crash when switching between 'States'.



  • Is there any restriction in using the number of states within a QML.
    I have qml which contains 11 states + 1 default states.
    When switching between specific state it crashes.
    I'm using 'variant Changed:' event to change the variable that is used for 'when condition'.

    import QtQuick 2.0
    import QtGraphicalEffects 1.12

    Item{
    id:afTemplate
    height: 360
    property alias af_hme_butn: af_hme_butn
    property alias af_menu_butn: af_menu_butn
    property alias af_fun_butn: af_fun_butn
    property alias menuScreenGrid: menuScreenGrid
    property alias afScreenIcons: afScreenIcons

    property int p_width: 585;
    width: p_width
    property string p_tpSide;
    property string p_line_color: "blue"
    property bool p_incomingCallNotification: false;
    property bool p_sendConfig: false
    property int p_cur_screen_ID  : m_isitleftside ? 108 : 208
    
    property bool m_isitleftside : p_tpSide == "left"
    property bool m_volume_adj : false
    property bool m_audio_src  : false
    property bool m_phone_src  : false
    property bool m_play_songs : false
    
    property int m_menu_state   : -1
    property int m_pmnu_state   : -1
    property int m_phme_scr_idx : -1
    property int m_home_scr_idx : 0 // change this to change the first screen
    property int m_menu_scr_idx : -1
    property int m_func_scr_idx : -1
    
    property int m_song_index   : -1
    property int m_usbsong_idx: 0
    property int m_btsong_idx: 0
    
    property int m_send_screen_id : -1
    
    property string m_heading_txt   : "Audio"
    property variant m_main_img     : ["music.png", "phone.png", "Settings.png"]
    
    property variant m_defaultstate : ["audio_src.png", "media-seek-backward.png","media-seek-forward.png"] //0.default
    property variant m_funcstate0   : ["back.png", "media-seek-backward.png","media-seek-forward.png"]      //1.streaming menuselected
    property variant m_funcstate1   : ["back.png", "textMessage.png", "outgoing_call.png"]
    property variant m_funcstate2   : ["back.png", "send_message.png", "outgoing_call.png"]
    property variant m_funcstate3   : ["cross.png", "textMessage.png", "tick.png"]
    property variant m_funcstate4   : ["cross.png", "send_message.png", "tick.png"]
    property variant m_funcstate5   : ["call_decline.png"]
    property variant m_funcstate6   : ["dummyImage.png"]
    property variant m_funcbtnImg   : [m_defaultstate,m_funcstate0,m_funcstate0,m_defaultstate,m_funcstate0,
        m_defaultstate,m_funcstate1,m_funcstate2,m_funcstate3,m_funcstate4,m_funcstate5,m_funcstate6]
    property variant m_funcbtnNum   : [3,3,3,3,3,3,3,3,3,3,1,0]
    
    property variant m_audio_img    : ["am-radio.png","fm-radio.png","Bluetooth.png","USB.png"]
    property variant m_phone_img    : ["Phone_Book.png","call_history.png"];
    property variant m_setng_img    : ["compass.png","swap.png"]
    property variant m_menu_img     : [m_audio_img,m_phone_img,m_setng_img]
    
    property variant m_audio_txt    : ["AM", "FM", "BT", "USB"]
    property variant m_phone_txt    : ["Contacts", "Recent Calls"]
    property variant m_setng_txt    : ["Compass", "Swap"]
    property variant m_menu_txt     : [m_audio_txt, m_phone_txt,m_setng_txt]
    
    property variant m_menu_offset  : [0,5,3]
    property variant m_screenID    : m_isitleftside ? [108,106,106,101] : [208,206,206,201]
    property variant m_listID      : m_isitleftside ? 109 : 209
    property variant m_searchID    : m_isitleftside ? 111 : 211
    property variant m_freeID      : m_isitleftside ? 105 : 201
    
    property variant m_contact_img: ["img_avatar-female.png","img_avatar-male.png","defaultContact.png"]
    property variant m_contactlist: ContactModel{}
    property variant m_msglist: MsgModel {}
    property variant m_usbsonglist: USB_SongsModel {}
    property variant m_btsonglist: BT_SongsModel {}
    property variant m_songlist: m_btsonglist;//m_audio_src ? m_usbsonglist : m_btsonglist
    
    property int m_nof_songs: m_songlist.count
    property variant m_artHeadingTxt: "ALBUM HEADING"
    property variant m_artAlbumName: "Text"
    property variant m_artArtistName: "text"
    property variant m_artImg:"img_avatar-female.png"
    
    //default actions
    //h0-m0-f0;h1-m5-f0;h2-m3-f0 : change source
    //h0-m1-f0;h0-m2-f0;h1-m6-f0;h1-m7-f0;h2-m4-f0 : go back
    //h0-m0-f1;h0-m1-f1;h0-m2-f1;h1-m5-f1;h2-m3-f1;h2-m4-f1 : seek UP
    //h0-m0-f2;h0-m1-f2;h0-m2-f2;h1-m5-f2;h2-m3-f2;h2-m4-f2 : seek DOWN
    
    /*
      m_menu_state - Description - menu - func button
      0 - default home screen - audio - source,seekup/down
      1 - BT/USB audio album art screen - audio - back,seekup/down
      2 - BT/USB audio song list screen - audio - back,seekup/down
      3 - default setting screen - settings - source,seekup/down
      4 - Compass animation screen - settings - back,seekup/down
      5 - default phone screen - phone - source,seekup/down
      6 - contact/recentcall contact list screen - phone - back,text message,call
      7 - contact/recentcall msg list screen - phone - back,send message, call
      8 - incoming call screen - phone - decline, text message, answer
      9 - incoming call msg list screen - decline, send message, answer
      10 - call connected - phone - decline
      11 - sending msg - phone - NO FUNCTION BUTTION
      12 - volume adjust - audio/phone - volume adj slider
     */
    signal sendButtonConfig(string msg)
    signal sendDisableSliderCtrlObj()
    signal sendImageToInformationPanel(string label, bool flag, string img)
    signal sendPasswordIndex(int index)
    signal sendScreenIDtoBackend(int screenID)
    signal swapLayout()
    
    Timer {
        id:incomingCallTimer; repeat: true; running: false; interval: 15000;
        onTriggered: p_incomingCallNotification = true;
    }
    Timer {
        id:msgTimer; repeat: false; running: m_menu_state == 11; interval: 1000;
        onTriggered: {m_func_scr_idx = 0;}
    }
    Timer {
        id:songsTimer; repeat: true; running: (m_play_songs && (m_menu_state < 8)); interval: 10000; triggeredOnStart: true;
        onTriggered: {//console.log("=====> Change song index :  @ : ",Qt.formatTime(new Date(), "hh:mm:ss"));
            if(m_song_index+1 >= m_nof_songs) m_song_index = 0;
            else m_song_index+=1;
    
            m_artAlbumName = "Album : " + m_songlist.get(m_song_index).album
            m_artHeadingTxt = m_songlist.get(m_song_index).name
            m_artArtistName = "Artist : " + m_songlist.get(m_song_index).artist
            m_artImg = "AlbumArt/" + m_songlist.get(m_song_index).art
        }
    }
    
    
    onM_home_scr_idxChanged: {
        if((m_home_scr_idx > -1) && (!p_incomingCallNotification)){
            console.log("ENTER : onM_home_scr_idxChanged : ",m_heading_txt,"Menu Screen : m_home_scr_idx : ",m_home_scr_idx, ", m_menu_state : ",m_menu_state)
            switch(m_home_scr_idx){
            case 1: m_menu_state = 5; break;
            default: m_menu_state = m_home_scr_idx ? 3 : 0;
            }
            //sendScreenIDtoBackend(m_screenID[m_home_scr_idx]);
            console.log("EXIT : onM_home_scr_idxChanged : ",m_heading_txt,"Menu Screen : m_home_scr_idx : ",m_home_scr_idx, ", m_menu_state : ",m_menu_state)
        }
    }
    
    onM_menu_scr_idxChanged: {
        if(m_menu_scr_idx > -1){
            console.log("ENTER : onM_menu_scr_idxChanged : ",m_heading_txt,"Menu Screen : m_home_scr_idx : ",m_home_scr_idx,",m_menu_scr_idx : ",m_menu_scr_idx, ", m_menu_state : ",m_menu_state)
            switch(m_home_scr_idx){
            case 1: m_menu_state = 6; m_phone_src = (m_menu_scr_idx == 1); break;
            case 2:
                if(m_menu_scr_idx == 0) m_menu_state = 4;
                else swapLayout();
                break;
            default: switch(m_menu_scr_idx){
                case 2: case 3: /*m_audio_src = (m_menu_scr_idx == 3);*/ m_menu_state = 1; break;
                        default: if(m_menu_state) { m_menu_state = 2; } else {m_play_songs=false;}break;
                }
                break;
            }
    
            //m_menu_scr_idx = -1;
            console.log("EXIT : onM_menu_scr_idxChanged : ",m_heading_txt,"Menu Screen : m_home_scr_idx : ",m_home_scr_idx,",m_menu_scr_idx : ",m_menu_scr_idx, ", m_menu_state : ",m_menu_state)
        }
    }
    
    onM_func_scr_idxChanged: {
        if(m_func_scr_idx > -1){
            console.log("ENTER : onM_func_scr_idxChanged : ",m_heading_txt,"Menu Screen : m_home_scr_idx : ",m_home_scr_idx,",m_func_scr_idx : ",m_func_scr_idx, ", m_menu_state : ",m_menu_state)
            //default actions
            //h0-m0-f0;h1-m5-f0;h2-m3-f0 : change source
            //h0-m1-f0;h0-m2-f0;h1-m6-f0;h1-m7-f0;h2-m4-f0 : go back
            //h0-m0-f1;h0-m1-f1;h0-m2-f1;h1-m5-f1;h2-m3-f1;h2-m4-f1 : seek UP
            //h0-m0-f2;h0-m1-f2;h0-m2-f2;h1-m5-f2;h2-m3-f2;h2-m4-f2 : seek DOWN
    
            if(m_menu_offset[m_home_scr_idx] === m_menu_state){
                switch(m_func_scr_idx){
                case 0: console.log("Change Audio Source here..."); break;
                case 1: console.log("Seek DOWN Audio Source here..."); break;
                case 2: console.log("Seek UP Audio Source here..."); break;
                }
            }else{
                switch(m_home_scr_idx){
                default:
                    switch(m_func_scr_idx){
                    case 1:/*if(check_seek())*/ console.log("Seek DOWN Audio Source here..."); break;
                    case 2:/*if(check_seek())*/ console.log("Seek UP Audio Source here..."); break;
                    default: --m_menu_state; m_play_songs = m_play_songs ? true : false;break;
                    }
                    break;
                case 1:
                    console.log("Phone screen logic here...");
                    switch(m_func_scr_idx){
                    case 1:
                        if((m_menu_state === 6) || (m_menu_state === 8)) m_menu_state +=1;
                        else m_menu_state = 11;
                        break;
                    case 2:
                        m_menu_state = 10;
                        break;
                    default:
                        if(p_incomingCallNotification) {
                            m_menu_state = m_pmnu_state;
                            m_home_scr_idx = m_phme_scr_idx;
                            p_incomingCallNotification = false;
                        }
                        else if((m_menu_state === 10) || (m_menu_state === 11)) m_menu_state = 6;
                        else --m_menu_state;
                        break;
                    }
                    break;
                }
            }
    
            m_func_scr_idx = -1;
            console.log("EXIT : onM_func_scr_idxChanged : ",m_heading_txt,"Menu Screen : m_home_scr_idx : ",m_home_scr_idx,",m_func_scr_idx : ",m_func_scr_idx, ", m_menu_state : ",m_menu_state)
        }
    }
    
    onP_incomingCallNotificationChanged: {
        if(p_incomingCallNotification){
    
            m_pmnu_state = (m_menu_state == 10) ? 6 : m_menu_state;
            m_phme_scr_idx = m_home_scr_idx;
            m_menu_state = 8;
            m_home_scr_idx = 1;
        }
    }
    
    onP_sendConfigChanged: {
        if(p_sendConfig){
            sendConfigToBackEnd()
            p_sendConfig = false;
        }
    }
    
    onM_send_screen_idChanged : {
        if(m_send_screen_id > -1){
            switch(m_send_screen_id){
            case 0: sendScreenIDtoBackend(m_searchID); break;
            case 1: sendScreenIDtoBackend(m_listID); break;
            case 2: sendScreenIDtoBackend(m_freeID); break;
            default: sendScreenIDtoBackend(m_screenID[m_home_scr_idx]); break;
            }
    
            m_send_screen_id = -1;
        }
    }
    
    onM_play_songsChanged: {
        console.log("----> onM_play_songsChanged", m_play_songs);
    }
    
    onM_audio_srcChanged: {
        if(m_audio_src) m_song_index = m_usbsong_idx;
        else m_song_index = m_btsong_idx;}
    
    onM_song_indexChanged: {
        if(m_audio_src) m_usbsong_idx = m_song_index;
        else m_btsong_idx = m_song_index;
    }
    
    
    
    Component.onCompleted: {
        console.log("Component.onCompleted from LayoutTemplate")
        m_menu_state = 0;
    }
    
    function sendConfigToBackEnd() {
        //console.log("Sending", p_tpSide , "Button Configuration To BackEnd...");
        if(topRect.visible){
            sendButtonConfig("Control,"+p_cur_screen_ID);
        }
    
        if(af_fun_butn.model){
            sendButtonConfig("Function,3");
        }
    }
    
    function recv_menu_butn_state(l_index, l_state){
        console.log( "LayoutTemplate : recv_menu_butn_state index : ",l_index, ",state : ",l_state, "STATE : ",state)
        if(l_index < (af_hme_butn.model+af_menu_butn.model)) {
            console.log("LayoutTemplate : recv_menu_butn_state : ",m_heading_txt,"Menu Screen : m_home_scr_idx : ",m_home_scr_idx,",m_menu_scr_idx : ",m_menu_scr_idx, ", m_menu_state : ",m_menu_state)
            if(l_index < af_hme_butn.model){af_hme_butn.itemAt(l_index).p_buttonState = l_state;}
            else {af_menu_butn.itemAt(l_index-af_hme_butn.model).p_buttonState = l_state;}}
    }
    
    function recv_func_butn_state(l_index, l_state){
        console.log( "LayoutTemplate : recv_func_butn_state index : ",l_index, ",state : ",l_state, "STATE : ",state)
        console.log("LayoutTemplate : recv_menu_butn_state : ",m_heading_txt,"Menu Screen : m_home_scr_idx : ",m_home_scr_idx,",m_menu_scr_idx : ",m_menu_scr_idx, ", m_menu_state : ",m_menu_state)
        switch(af_fun_butn.model) {
        case 1: af_fun_butn.itemAt(0).p_buttonState = l_state; break;
        case 3: af_fun_butn.itemAt(l_index).p_buttonState = l_state;break;
        default:break;
        }
    }
    
    states: [
        State {
            name: "audioScreen"
            when: ((afTemplate.m_menu_state === 0) && (m_home_scr_idx === 0))
            PropertyChanges { target: afTemplate; m_send_screen_id: 3; m_play_songs : m_play_songs ? true : false;}
        },
        State {
            name: "artScreen"
            when: ((afTemplate.m_menu_state === 1) && (m_home_scr_idx === 0))
            PropertyChanges { target: homeScreenContainer; visible: false; }
            PropertyChanges { target: artScreenContainer; visible: true; }
            PropertyChanges { target: listScreenContainer; visible: false; }
            PropertyChanges { target: topRect; color: "#000000"; }
            PropertyChanges { target: afTemplate; m_heading_txt: /*m_audio_src ? "USB Audio" : */"Bluetooth Audio"; /*m_send_screen_id: 3;*/ m_play_songs: true}
            PropertyChanges { target: artHeadingTxt; visible: true; }
            PropertyChanges { target: artAlbumName; visible: true; }
            PropertyChanges { target: artArtistName; visible: true; }
        },
        State {
            name: "songslistScreen"
            when: ((afTemplate.m_menu_state === 2) && (m_home_scr_idx === 0))
            PropertyChanges { target: homeScreenContainer; visible: false; }
            PropertyChanges { target: artScreenContainer; visible: false; }
            PropertyChanges { target: listScreenContainer; visible: true; }
            PropertyChanges { target: compassUi;visible: false;}
            PropertyChanges { target: topRect; color: "#000000"; }
            PropertyChanges { target: afTemplate; m_heading_txt: m_audio_src ? "USB Audio" : "Bluetooth Audio"; m_send_screen_id: 1; m_play_songs: true}
            PropertyChanges { target: listLayout; pObjName:m_songlist; p_listCount: m_songlist.count;}
        },
        State {
            name: "settingsScreen"
            when: ((afTemplate.m_menu_state === 3) && (m_home_scr_idx === 2))
            PropertyChanges { target: menuScreenGrid; spacing: 112; columns: 2; }
            PropertyChanges { target: bgImg; source: "pics/settings_panel_bg_img.png"; }
            PropertyChanges { target: afTemplate; m_heading_txt: "Settings"; m_send_screen_id: 3; m_play_songs: m_play_songs ? true : false;}
    
        },
        State {
            name: "compassScreen"
            when: ((afTemplate.m_menu_state === 4) && (m_home_scr_idx === 2))
            PropertyChanges { target: homeScreenContainer; visible: false; }
            PropertyChanges { target: artScreenContainer; visible: false; }
            PropertyChanges { target: listScreenContainer; visible: true;}
            PropertyChanges { target: compassUi;visible: true;}
            PropertyChanges { target: topRect; color: "#000000"; }
            PropertyChanges { target: afTemplate; m_heading_txt: "Compass"; m_send_screen_id: 2; m_play_songs: m_play_songs ? true : false;}
            PropertyChanges { target: artHeadingTxt; visible: false; }
            PropertyChanges { target: artAlbumName; visible: false; }
            PropertyChanges { target: artArtistName; visible: false; }
            PropertyChanges { target: artImg; anchors.leftMargin: 217; }
            PropertyChanges { target: listbgImg; source: "pics/settings_panel_bg_img.png"; }
        },
        State {
            name: "phoneScreen"
            when: ((afTemplate.m_menu_state === 5) && (m_home_scr_idx === 1))
            PropertyChanges { target: menuScreenGrid; spacing: 112; columns: 2; }
            PropertyChanges { target: bgImg; source: "pics/phone_panel_bg_img.png"; mirror: true}
            PropertyChanges { target: afTemplate; m_heading_txt: "Phone"; m_send_screen_id: 3; m_play_songs: m_play_songs ? true : false;}
        },
        State {
            name: "phonelistScreen"
            when: ((afTemplate.m_menu_state === 6) && (m_home_scr_idx === 1))
            PropertyChanges { target: homeScreenContainer; visible: false; }
            PropertyChanges { target: artScreenContainer; visible: false; }
            PropertyChanges { target: listScreenContainer; visible: true;}
            PropertyChanges { target: compassUi;visible: false;}
            PropertyChanges { target: topRect; color: "#000000"; }
            PropertyChanges { target: afTemplate; m_heading_txt: m_phone_src ? "Recent Calls" : "Contacts"; m_send_screen_id: 1; m_play_songs: m_play_songs ? true : false;}
            PropertyChanges { target: listLayout; p_showImg:m_phone_src; pObjName:m_contactlist; p_listCount:m_contactlist.count;}
            PropertyChanges { target: listbgImg; source: "pics/phone_panel_bg_img.png"; mirror: true}
        },
        State {
            name: "msglistScreen"
            when: (((afTemplate.m_menu_state === 7) || (afTemplate.m_menu_state === 9)) && (m_home_scr_idx === 1))
            PropertyChanges { target: homeScreenContainer; visible: false; }
            PropertyChanges { target: artScreenContainer; visible: false; }
            PropertyChanges { target: listScreenContainer; visible: true; }
            PropertyChanges { target: compassUi;visible: false;}
            PropertyChanges { target: topRect; color: "#000000"; }
            PropertyChanges { target: afTemplate; m_heading_txt: "Choose Message to Send"; m_send_screen_id: 1; m_play_songs: m_play_songs ? true : false;}
            PropertyChanges { target: listLayout; pObjName:m_msglist; p_listCount:m_msglist.count;}
            PropertyChanges { target: listbgImg; source: "pics/phone_panel_bg_img.png"; mirror: true}
        },
        State {
            name: "incomingCallAlertScreen"
            when: ((afTemplate.m_menu_state === 8) && (m_home_scr_idx === 1))
            PropertyChanges { target: homeScreenContainer; visible: false; }
            PropertyChanges { target: artScreenContainer; visible: true; }
            PropertyChanges { target: listScreenContainer; visible: false; }
            PropertyChanges { target: topRect; color: "#000000"; }
            PropertyChanges { target: afTemplate; m_heading_txt: "Incoming Call..."; m_send_screen_id: 2;m_play_songs: m_play_songs ? true : false;}
            PropertyChanges { target: artHeadingTxt; visible: true; }
            PropertyChanges { target: artAlbumName; visible: false; }
            PropertyChanges { target: artArtistName; visible: false; }
        },
        State {
            name: "callConnectedScreen"
            when: ((afTemplate.m_menu_state === 10) && (m_home_scr_idx === 1))
            PropertyChanges { target: homeScreenContainer; visible: false; }
            PropertyChanges { target: artScreenContainer; visible: true; }
            PropertyChanges { target: listScreenContainer; visible: false; }
            PropertyChanges { target: topRect; color: "#000000"; }
            PropertyChanges { target: afTemplate; m_heading_txt: "Active Call"; m_send_screen_id: 2;m_play_songs: m_play_songs ? true : false;}
            PropertyChanges { target: artHeadingTxt; visible: true; }
            PropertyChanges { target: artArtistName; visible: false; }
            PropertyChanges { target: artAlbumName; visible: false; }
        },
        State {
            name: "msgSendingScreen"
            when: ((afTemplate.m_menu_state === 11) && (m_home_scr_idx === 1))
            PropertyChanges { target: homeScreenContainer; visible: false; }
            PropertyChanges { target: artScreenContainer; visible: true; }
            PropertyChanges { target: listScreenContainer; visible: false; }
            PropertyChanges { target: topRect; color: "#000000"; }
            PropertyChanges { target: afTemplate; m_heading_txt: "Sending Message"; m_send_screen_id: 2;m_play_songs: m_play_songs ? true : false;}
            PropertyChanges { target: artHeadingTxt; visible: true; }
            PropertyChanges { target: artAlbumName; visible: false; }
            PropertyChanges { target: artArtistName; visible: false; }
            PropertyChanges { target: artHeadingTxt; anchors.verticalCenterOffset: 50; }
            PropertyChanges { target: artImg; anchors.verticalCenterOffset: 50; }
        }
    ]
    
    transitions: [
        Transition { from: "*"; to: "artScreen"; onRunningChanged: {
             if(!running){
                m_send_screen_id = 3;
                 console.log("--------------------------> Transition Completed ---------------->")
             }
            }
        }
    ]
    

    }


Log in to reply