Qt error messages when using dynamically created QML items?

前端 未结 1 928
一生所求
一生所求 2021-01-19 00:55

Is it possible to get Qt error messages when using dynamically created items?

I\'ve installed a message handler to capture Qt output at run time:

qIn         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-19 01:25

    You should read and follow documentation.

    What you do not check is that component.status must be equal to Component.Ready before calling to component.createObject.

    If the file somehow failed to load, as it does not parse correctly, component.status will be equal to Component.Error, and you should call errorString() to get more information.

    var component = Qt.createComponent( "config.qml" );
    if( component.status != Component.Ready )
    {
        if( component.status == Component.Error )
            console.debug("Error:"+ component.errorString() );
        return; // or maybe throw
    }
    var dlg = component.createObject( parentId, {} );
    

    Anyway you should always assert component.status == Component.Ready before calling createObject().

    0 讨论(0)
提交回复
热议问题