From 4974262675269ce56397326c86875dc5e540357c Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Sat, 26 Sep 2020 13:46:35 +0200 Subject: [PATCH] avoid crashes, when the Qt/Quick layout module is not available --- playground/grids/GridQuick.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/playground/grids/GridQuick.cpp b/playground/grids/GridQuick.cpp index 01c8c235..b1caaef1 100644 --- a/playground/grids/GridQuick.cpp +++ b/playground/grids/GridQuick.cpp @@ -6,6 +6,7 @@ #include "GridQuick.h" #include #include +#include static QQuickItem* createQml( const char* qmlCode ) { @@ -14,6 +15,9 @@ static QQuickItem* createQml( const char* qmlCode ) QQmlComponent component( &engine ); component.setData( qmlCode, QUrl() ); + if ( component.status() != QQmlComponent::Ready ) + qWarning() << component.errorString(); + return qobject_cast< QQuickItem* >( component.create() ); } @@ -74,14 +78,17 @@ void GridQuick::insert( const QByteArray& colorName, rectangle->setImplicitWidth( 50 ); rectangle->setImplicitHeight( 50 ); + rectangle->setProperty( "color", QColor( colorName.constData() ) ); - auto props = attachedProperties( rectangle ); - props->setProperty( "row", row ); - props->setProperty( "column", column ); - props->setProperty( "rowSpan", rowSpan ); - props->setProperty( "columnSpan", columnSpan ); - props->setProperty( "fillWidth", true ); - props->setProperty( "fillHeight", true ); + if ( auto props = attachedProperties( rectangle ) ) + { + props->setProperty( "row", row ); + props->setProperty( "column", column ); + props->setProperty( "rowSpan", rowSpan ); + props->setProperty( "columnSpan", columnSpan ); + props->setProperty( "fillWidth", true ); + props->setProperty( "fillHeight", true ); + } } void GridQuick::setSpacing( Qt::Orientations orientations, int spacing )