<commit_before>#include "qmlpromise.h"

#include <QQmlComponent>
#include <QQmlEngine>
#include <QDebug>

QmlPromise::QmlPromise(QObject* parent)
    : QObject(parent) {
    QQmlComponent promiserComponent(qmlEngine(parent));
    promiserComponent.setData("import QuickPromise 1.0\nPromise {}", QUrl());
    internalPromise = promiserComponent.create();

    QQmlEngine::setObjectOwnership(internalPromise, QQmlEngine::JavaScriptOwnership);
    connect(internalPromise, &QObject::destroyed, this, [this] {
        // Probably won't happen often, if ever, but if it does it could provide useful insights vis a vis debugging
        qDebug() << "Promise{} was garbage collected while QmlPromise still valid";
        internalPromise = nullptr;
    });
    connect(internalPromise, SIGNAL(fulfilled(QVariant)), this, SIGNAL(fulfilled(QVariant)));
    connect(internalPromise, SIGNAL(rejected(QVariant)), this, SIGNAL(rejected(QVariant)));
    connect(internalPromise, SIGNAL(settled(QVariant)), this, SIGNAL(settled()));
    connect(this, &QmlPromise::fulfilled, [this] { wasFulfilled = true; });
    connect(this, &QmlPromise::rejected, [this] { wasRejected = true; });
}

QmlPromise::~QmlPromise() {
}

bool QmlPromise::isFulfilled() {
    return internalPromise? internalPromise->property("isFulfilled").toBool() : wasFulfilled;<commit_msg>Show meaningful error when unable to find QML engine<commit_after>#include "qmlpromise.h"

#include <QQmlComponent>
#include <QQmlEngine>
#include <QDebug>

QmlPromise::QmlPromise(QObject* parent)
    : QObject(parent) {
    auto engine = qmlEngine(parent);
    if (engine == nullptr)
        qFatal("Could not find QML engine. Unable to continue.");

    QQmlComponent promiserComponent(qmlEngine(parent));
    promiserComponent.setData("import QuickPromise 1.0\nPromise {}", QUrl());
    internalPromise = promiserComponent.create();

    QQmlEngine::setObjectOwnership(internalPromise, QQmlEngine::JavaScriptOwnership);
    connect(internalPromise, &QObject::destroyed, this, [this] {
        // Probably won't happen often, if ever, but if it does it could provide useful insights vis a vis debugging
        qDebug() << "Promise{} was garbage collected while QmlPromise still valid";
        internalPromise = nullptr;
    });
    connect(internalPromise, SIGNAL(fulfilled(QVariant)), this, SIGNAL(fulfilled(QVariant)));
    connect(internalPromise, SIGNAL(rejected(QVariant)), this, SIGNAL(rejected(QVariant)));
    connect(internalPromise, SIGNAL(settled(QVariant)), this, SIGNAL(settled()));
    connect(this, &QmlPromise::fulfilled, [this] { wasFulfilled = true; });
    connect(this, &QmlPromise::rejected, [this] { wasRejected = true; });
}

QmlPromise::~QmlPromise() {
}

bool QmlPromise::isFulfilled() {
    return internalPromise? internalPromise->property("isFulfilled").toBool() : wasFulfilled;
{'fraction_non_alphanumeric': 0.13157894736842105, 'fraction_numerical': 0.0014035087719298245, 'mean_word_length': 5.630232558139535, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4575285', 'n_tokens_mistral': 870, 'n_tokens_neox': 833, 'n_words': 189}