Skip to content

Commit

Permalink
Better error messages when component can't be loaded (#175)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina authored Feb 5, 2021
1 parent 7863c80 commit 64c907c
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/Plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,41 @@ void Plugin::Load(const tinyxml2::XMLElement *_pluginElem)

// Instantiate plugin QML file into a component
std::string qmlFile(":/" + filename + "/" + filename + ".qml");
if (!QFile(QString::fromStdString(qmlFile)).exists())
{
ignerr << "Can't find [" << qmlFile
<< "]. Are you sure it was added to the .qrc file?" << std::endl;
return;
}

QQmlComponent component(App()->Engine(), QString::fromStdString(qmlFile));
if (component.isError())
{
std::stringstream errors;
errors << "Failed to instantiate QML file [" << qmlFile << "]."
<< std::endl;
for (auto error : component.errors())
{
errors << "* " << error.toString().toStdString() << std::endl;
}
ignerr << errors.str();
return;
}
if (!component.isReady())
{
ignerr << "Component from QML file [" << qmlFile
<< "] is not ready. Progress: " << component.progress()
<< " / 1.0" << std::endl;
return;
}

// Create an item for the plugin
this->dataPtr->pluginItem =
qobject_cast<QQuickItem *>(component.create(this->dataPtr->context));
if (!this->dataPtr->pluginItem)
{
ignerr << "Failed to instantiate QML file [" << qmlFile << "]." << std::endl
<< "* Are you sure it's been added to the .qrc file?" << std::endl
<< "* Are you sure the file is valid QML? "
<< "Are you sure the file is valid QML? "
<< "You can check with the `qmlscene` tool" << std::endl;
return;
}
Expand Down

0 comments on commit 64c907c

Please sign in to comment.