aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools/qtc-askpass/qtc-askpass-main.cpp
blob: 988c24f15ec20d8fe6128f209abb1e357f789619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include <QApplication>
#include <QInputDialog>
#include <QTimer>
#include <iostream>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTimer::singleShot(0, [] {
        QInputDialog dlg;
        const QStringList appArgs = qApp->arguments();
        QString labelText = QCoreApplication::translate("qtc-askpass",
                                                        "Password required.");
        if (appArgs.count() > 1)
            labelText.append('\n').append(appArgs.at(1));
        dlg.setLabelText(labelText);
        dlg.setTextEchoMode(QLineEdit::Password);
        if (dlg.exec() == QDialog::Accepted)
            std::cout << qPrintable(dlg.textValue()) << std::endl;
    });
    return app.exec();
}