diff --git a/examples/mvvmcore/SampleCore/settings.xml b/examples/mvvmcore/SampleCore/settings.xml
index 8f2412a..80fbb91 100644
--- a/examples/mvvmcore/SampleCore/settings.xml
+++ b/examples/mvvmcore/SampleCore/settings.xml
@@ -109,5 +109,8 @@
+
diff --git a/src/mvvmquick/ErrorLabel.qml b/src/mvvmquick/ErrorLabel.qml
new file mode 100644
index 0000000..de4c1bb
--- /dev/null
+++ b/src/mvvmquick/ErrorLabel.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.10
+import QtQuick.Controls 2.3
+
+Label {
+ text: qsTr("Failed to load edit view!")
+ color: "#800000"
+}
diff --git a/src/mvvmquick/inputviewfactory.cpp b/src/mvvmquick/inputviewfactory.cpp
index c11bc78..15fc8f8 100644
--- a/src/mvvmquick/inputviewfactory.cpp
+++ b/src/mvvmquick/inputviewfactory.cpp
@@ -50,7 +50,7 @@ QUrl InputViewFactory::getInputUrl(const QByteArray &type, const QVariantMap &vi
return QStringLiteral("qrc:/qtmvvm/inputs/RadioListEdit.qml");
else {
logCritical() << "Failed to find any input view for input type:" << type;
- return QUrl();
+ return QStringLiteral("qrc:/qtmvvm/inputs/ErrorLabel.qml");
}
}
diff --git a/src/mvvmquick/qtmvvmquick_module.qrc b/src/mvvmquick/qtmvvmquick_module.qrc
index bb7821f..ebee3b9 100644
--- a/src/mvvmquick/qtmvvmquick_module.qrc
+++ b/src/mvvmquick/qtmvvmquick_module.qrc
@@ -9,6 +9,7 @@
UrlField.qml
Switch.qml
RadioListEdit.qml
+ ErrorLabel.qml
BoolDelegate.qml
diff --git a/src/mvvmwidgets/inputwidgetfactory.cpp b/src/mvvmwidgets/inputwidgetfactory.cpp
index b9e20a8..b99226b 100644
--- a/src/mvvmwidgets/inputwidgetfactory.cpp
+++ b/src/mvvmwidgets/inputwidgetfactory.cpp
@@ -1,6 +1,7 @@
#include "inputwidgetfactory.h"
#include "inputwidgetfactory_p.h"
-#include
+
+#include
#include
#include
@@ -13,6 +14,8 @@
#include
+#include
+
using namespace QtMvvm;
InputWidgetFactory::InputWidgetFactory() :
@@ -64,10 +67,8 @@ QWidget *InputWidgetFactory::createInput(const QByteArray &type, QWidget *parent
widget = edit;
} else if(type == "selection" || type == "list")
widget = new SelectComboBox(parent);
- else {
- logCritical() << "Failed to find any input view for input type:" << type;
- return nullptr; //TODO throw?
- }
+ else
+ throw PresenterException("Unable to find an input view for type" + type);
for(auto it = viewProperties.constBegin(); it != viewProperties.constEnd(); it++)
widget->setProperty(qUtf8Printable(it.key()), it.value());
diff --git a/src/mvvmwidgets/settingsdialog.cpp b/src/mvvmwidgets/settingsdialog.cpp
index 4e2e3ae..769d5b4 100644
--- a/src/mvvmwidgets/settingsdialog.cpp
+++ b/src/mvvmwidgets/settingsdialog.cpp
@@ -186,23 +186,28 @@ void SettingsDialogPrivate::createEntry(const SettingsElements::Entry &entry, QW
});
content = btn;
} else {
- auto widgetFactory = WidgetsPresenterPrivate::currentPresenter()->inputWidgetFactory();
- content = widgetFactory->createInput(entry.type, sectionWidget, entry.properties);
- if(!content) {
- logWarning() << "Failed to create settings widget for type" << entry.type;
- return;
+ try {
+ auto widgetFactory = WidgetsPresenterPrivate::currentPresenter()->inputWidgetFactory();
+ content = widgetFactory->createInput(entry.type, sectionWidget, entry.properties);
+ auto property = content->metaObject()->userProperty();
+ property.write(content, viewModel->loadValue(entry.key, entry.defaultValue));
+ if(property.hasNotifySignal()) {
+ auto changedSlot = metaObject()->method(metaObject()->indexOfSlot("propertyChanged()"));
+ connect(content, property.notifySignal(),
+ this, changedSlot);
+ } else
+ changedEntries.insert(content);
+
+ entryMap.insert(content, {entry, property});
+ } catch (PresenterException &e) {
+ logWarning() << "Failed to create settings widget for key"
+ << entry.key
+ << "with error:" << e.what();
+ content = new QLabel(tr("Failed to load edit view!"), sectionWidget);
+ auto pal = content->palette();
+ pal.setColor(QPalette::WindowText, Qt::darkRed);
+ content->setPalette(pal);
}
-
- auto property = content->metaObject()->userProperty();
- property.write(content, viewModel->loadValue(entry.key, entry.defaultValue));
- if(property.hasNotifySignal()) {
- auto changedSlot = metaObject()->method(metaObject()->indexOfSlot("propertyChanged()"));
- connect(content, property.notifySignal(),
- this, changedSlot);
- } else
- changedEntries.insert(content);
-
- entryMap.insert(content, {entry, property});
}
auto label = new QLabel(entry.title + tr(":"), sectionWidget);
diff --git a/src/mvvmwidgets/widgetspresenter.cpp b/src/mvvmwidgets/widgetspresenter.cpp
index 3a89acb..7275990 100644
--- a/src/mvvmwidgets/widgetspresenter.cpp
+++ b/src/mvvmwidgets/widgetspresenter.cpp
@@ -301,11 +301,6 @@ void WidgetsPresenter::presentMessageBox(const MessageConfig &config, QPointer result)
{
auto input = d->inputViewFactory->createInput(config.subType(), nullptr, config.viewProperties());
- if(!input) {
- throw PresenterException(QByteArrayLiteral("Unable to find an input for type") +
- config.subType());
- }
-
QWidget *parent = nullptr;
if(!config.viewProperties().value(QStringLiteral("modal"), false).toBool())
parent = QApplication::activeWindow();