Files
oak-editor/app/project/projectloadmanager.cpp
T
itsmattkc 0ea98be443 ensure objects are in the correct thread when loading
Since we load in a separate thread, when the QObject based objects are
instantiated, they're created with affinity to that separate thread. Now we
specifically ensure they are moved to the main thread after their creation.
2020-01-14 00:10:21 +11:00

50 lines
1.0 KiB
C++

#include "projectloadmanager.h"
#include <QFile>
#include <QXmlStreamReader>
ProjectLoadManager::ProjectLoadManager(const QString &filename) :
filename_(filename)
{
}
void ProjectLoadManager::Start()
{
QFile project_file(filename_);
if (project_file.open(QFile::ReadOnly | QFile::Text)) {
QXmlStreamReader reader(&project_file);
while (!reader.atEnd()) {
reader.readNext();
if (reader.isStartElement()) {
if (reader.name() == "version") {
reader.readNext();
qDebug() << "Project version:" << reader.text();
} else if (reader.name() == "project") {
ProjectPtr project = std::make_shared<Project>();
project->set_filename(filename_);
project->Load(&reader);
// Ensure project is in main thread
moveToThread(qApp->thread());
emit ProjectLoaded(project);
}
}
}
if (reader.hasError()) {
qDebug() << "Found XML error:" << reader.errorString();
}
project_file.close();
}
emit Finished();
}