Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Warning: QQmlComponent: Component is not ready

Tags:

qt5

qml

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:

qInstallMessageHandler( myMessageOutput );

I load a basic qml file into a QQuickView and it works fine. If there are errors in the qml source they're displayed in my log. If I dynamically create items and they contain errors it fails without any message.

I create the dynamic objects like this:

var component = Qt.createComponent( "config.qml" );
var dlg = component.createObject( parentId, {} );

The only error I receive is the following:

'qml\qqmlcomponent.cpp':845 function: 'QObject* QQmlComponentPrivate::beginCreate(QQmlContextData*)'|Qt Warning: QQmlComponent: Component is not ready

This error is written for any kind of problem in the qml it's trying to load.

like image 365
Jay Avatar asked Aug 02 '13 18:08

Jay


1 Answers

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().

like image 194
Arpegius Avatar answered Dec 17 '22 20:12

Arpegius