36 lines
874 B
C++
36 lines
874 B
C++
#include <QApplication>
|
|
#include <QFileDialog>
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
#include <QDebug>
|
|
#include <iostream>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
QApplication app(argc, argv);
|
|
|
|
QList<QUrl> urls = QFileDialog::getOpenFileUrls(nullptr, "Select File", QUrl(), "All Files (*.*)");
|
|
if (urls.empty()) return 1;
|
|
|
|
QUrl url = urls.first();
|
|
if (!url.isValid() || !url.isLocalFile()) return 1;
|
|
|
|
QFile file(url.toLocalFile());
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
std::cerr << "Failed to open file" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
QTextStream in(&file);
|
|
QString line = in.readLine();
|
|
bool ok;
|
|
int number = line.toInt(&ok);
|
|
|
|
if (!ok) {
|
|
std::cerr << "Failed to read integer from file" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
std::cout << number * 2 << std::endl;
|
|
return 0;
|
|
}
|