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

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

    QString fileName = QFileDialog::getSaveFileName(nullptr, "Select File", "", "All Files (*.*)");

    if (fileName.isEmpty()) {
        qDebug() << "File selection cancelled.";
        return 0;
    }

    QFile file(fileName);

    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:" << fileName;

    return 0;
}
