Skip to content

Instantly share code, notes, and snippets.

@foxoman
Created August 15, 2020 11:58
Show Gist options
  • Save foxoman/d1b8bb9b6c4356ed925b90a4c5b0963f to your computer and use it in GitHub Desktop.
Save foxoman/d1b8bb9b6c4356ed925b90a4c5b0963f to your computer and use it in GitHub Desktop.
Full Qt Console Application with CommandLine Parser!
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QtDebug>
#include <QTimer>
static QTextStream qin( stdin, QIODevice::ReadOnly );
using qStr = const QString;
int main( int argc, char* argv[] )
{
QCoreApplication app( argc, argv );
app.setApplicationName( QStringLiteral( "System Information Console" ) );
app.setOrganizationName( QStringLiteral( "Foxoman.Net" ) );
app.setOrganizationDomain( QStringLiteral( "foxoman.net" ) );
app.setApplicationVersion( QStringLiteral( "1.1.0" ) );
qStr green = QStringLiteral( "\033[1;32m" );
qStr yellow = QStringLiteral( "\033[01;33m" );
qStr clr = QStringLiteral( "\033[0m" );
QSysInfo qSys;
const QString logo = QStringLiteral( R"(
╭────────────────────────────────────────────────────────────────╮
│ │
│ SYSTEM INFORMATION CONSOLE │
│ Build By: Sultan Al Isaiee │
│ www.foxoman.net │
│ 2020 @ foxoman │
│ Build with 💖 Using Qt %VERSION │
╰────────────────────────────────────────────────────────────────╯
)" )
.replace( "%VERSION", QT_VERSION_STR );
QCommandLineParser parser;
parser.setApplicationDescription( yellow + logo + clr );
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption hostOption( QStringList() << "n"
<< "host-name",
QStringLiteral( "Returns this machine's host name." ) );
parser.addOption( hostOption );
QCommandLineOption idOption( QStringList() << "i"
<< "machine-id",
QStringLiteral( "Returns a unique ID for this machine." ) );
parser.addOption( idOption );
QCommandLineOption bootOption(
QStringList() << "b"
<< "boot-id",
QStringLiteral( "Returns a unique ID for this machine's boot." ) );
parser.addOption( bootOption );
QCommandLineOption buildOption(
QStringList() << "d"
<< "build-abi",
QStringLiteral( "Returns the full architecture string that Qt was compiled for." ) );
parser.addOption( buildOption );
QCommandLineOption cpuOption(
QStringList() << "c"
<< "current-cpu",
QStringLiteral(
"Returns the architecture of the CPU that the application is running on." ) );
parser.addOption( cpuOption );
QCommandLineOption kernelOption(
QStringList() << "k"
<< "kernel-type",
QStringLiteral(
"Returns the type of the operating system kernel Qt was compiled for." ) );
parser.addOption( kernelOption );
QCommandLineOption kernelVOption(
QStringList() << "r"
<< "kernel-version",
QStringLiteral( "Returns the release version of the operating system kernel." ) );
parser.addOption( kernelVOption );
QCommandLineOption productOption(
QStringList() << "p"
<< "product",
QStringLiteral( "Returns a form of product Type and product Version,"
"containing other tokens like the operating system type, codenames"
"and other information." ) );
parser.addOption( productOption );
parser.process( app );
if ( parser.isSet( hostOption ) ) {
qInfo().noquote() << green << "➡️ Machine Host Name:" << clr << qSys.machineHostName();
} else if ( parser.isSet( idOption ) ) {
qInfo().noquote() << green << "➡️ Machine Unique ID:" << clr << qSys.machineUniqueId();
} else if ( parser.isSet( bootOption ) ) {
qInfo().noquote() << green << "➡️ Boot Unique ID:" << clr << qSys.bootUniqueId();
} else if ( parser.isSet( buildOption ) ) {
qInfo().noquote() << green << "➡️ Build ABI:" << clr << qSys.buildAbi();
} else if ( parser.isSet( cpuOption ) ) {
qInfo().noquote() << green << "➡️ Current CPU Architecture:" << clr
<< qSys.currentCpuArchitecture();
} else if ( parser.isSet( kernelOption ) ) {
qInfo().noquote() << green << "➡️ Kernel Type:" << clr << qSys.kernelType();
} else if ( parser.isSet( kernelVOption ) ) {
qInfo().noquote() << green << "➡️ Kernel Version:" << clr << qSys.kernelVersion();
} else if ( parser.isSet( productOption ) ) {
qInfo().noquote() << green << "➡️ Product Name:" << clr << qSys.prettyProductName();
} else {
parser.showHelp();
}
QTimer::singleShot( 0, &app, &QCoreApplication::quit );
return app.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment