#include <QApplication>
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <iostream>
#include <QUrl>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    QUrl url = QFileDialog::getSaveFileUrl(nullptr, "Select File", QUrl(), "All Files (*.*)");
    if (!url.isValid() || !url.isLocalFile()) {
        qDebug() << "File selection cancelled.";
        return 1;
    }

    QFile file(url.toLocalFile());
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
        std::cerr << "Failed to open file for writing: " << file.errorString().toStdString() << std::endl;
        return 1;
    }

    QTextStream out(&file);
    out << "foo";
    file.close();

    qDebug() << "Successfully wrote \"foo\" to:" << url.toLocalFile();

    return 0;
}
