#include <QApplication>
#include <QFileDialog>
#include <QSemaphore>
#include <QThread>
#include <QTextStream> // Still needed for parsing the content
#include <QDebug>
#include <iostream>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    
    auto fileContentReady = [](const QString &fileName, const QByteArray &fileContent) {
        if (fileName.isEmpty() || !QFile(fileName).exists()) {
            std::cerr << "Failed to open file" << std::endl;
            return;
        }
        
        QString contentStr(fileContent);
        QTextStream in(&contentStr);
        QString line = in.readLine();
        
        bool ok;
        int number = line.toInt(&ok);
        if (!ok) {
            std::cerr << "Failed to read integer from file content" << std::endl;
            return;
        }
        
        std::cout << number * 2 << std::endl;
    };
    
    QFileDialog::getOpenFileContent("All Files (*.*)", fileContentReady);
}