avoid crashes, when the Qt/Quick layout module is not available

This commit is contained in:
Uwe Rathmann 2020-09-26 13:46:35 +02:00
parent b3d8598965
commit 4974262675
1 changed files with 14 additions and 7 deletions

View File

@ -6,6 +6,7 @@
#include "GridQuick.h" #include "GridQuick.h"
#include <QQuickItem> #include <QQuickItem>
#include <QtQml> #include <QtQml>
#include <QDebug>
static QQuickItem* createQml( const char* qmlCode ) static QQuickItem* createQml( const char* qmlCode )
{ {
@ -14,6 +15,9 @@ static QQuickItem* createQml( const char* qmlCode )
QQmlComponent component( &engine ); QQmlComponent component( &engine );
component.setData( qmlCode, QUrl() ); component.setData( qmlCode, QUrl() );
if ( component.status() != QQmlComponent::Ready )
qWarning() << component.errorString();
return qobject_cast< QQuickItem* >( component.create() ); return qobject_cast< QQuickItem* >( component.create() );
} }
@ -74,14 +78,17 @@ void GridQuick::insert( const QByteArray& colorName,
rectangle->setImplicitWidth( 50 ); rectangle->setImplicitWidth( 50 );
rectangle->setImplicitHeight( 50 ); rectangle->setImplicitHeight( 50 );
rectangle->setProperty( "color", QColor( colorName.constData() ) );
auto props = attachedProperties( rectangle ); if ( auto props = attachedProperties( rectangle ) )
{
props->setProperty( "row", row ); props->setProperty( "row", row );
props->setProperty( "column", column ); props->setProperty( "column", column );
props->setProperty( "rowSpan", rowSpan ); props->setProperty( "rowSpan", rowSpan );
props->setProperty( "columnSpan", columnSpan ); props->setProperty( "columnSpan", columnSpan );
props->setProperty( "fillWidth", true ); props->setProperty( "fillWidth", true );
props->setProperty( "fillHeight", true ); props->setProperty( "fillHeight", true );
}
} }
void GridQuick::setSpacing( Qt::Orientations orientations, int spacing ) void GridQuick::setSpacing( Qt::Orientations orientations, int spacing )