Skip to content

Instantly share code, notes, and snippets.

@manashmandal
Created March 30, 2016 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manashmandal/ad1b61f075ad76ad6b76ca42de5624b4 to your computer and use it in GitHub Desktop.
Save manashmandal/ad1b61f075ad76ad6b76ca42de5624b4 to your computer and use it in GitHub Desktop.
Qt Quick 2
#include "adminpriv.h"
#include "ui_adminpriv.h"
#include <QSettings>
#include <QDebug>
//Admin privilege checker string
#define ADMIN_TEST_STRING "HKEY_LOCAL_MACHINE"
#define ADMIN_DEFAULT_KEY "(Default)"
//If Admin privilege was activated or not
#define ADMIN_CHECK_OK "Administrator privilege was activated"
#define ADMIN_CHECK_FAILED "Administrator privilege not found"
AdminPriv::AdminPriv(QWidget *parent) :
QWidget(parent),
ui(new Ui::AdminPriv)
{
ui->setupUi(this);
}
AdminPriv::~AdminPriv()
{
delete ui;
}
void AdminPriv::on_checkButton_clicked()
{
QSettings adminPrivSettings(ADMIN_TEST_STRING, QSettings::NativeFormat);
QVariant currentAdminStatus = adminPrivSettings.value(ADMIN_DEFAULT_KEY);
adminPrivSettings.setValue(ADMIN_DEFAULT_KEY, currentAdminStatus);
adminPrivSettings.sync();
//Check for admin privilege mode
if (adminPrivSettings.status() == QSettings::AccessError){
ui->statusLabel->setText(QString(ADMIN_CHECK_FAILED));
} else {
ui->statusLabel->setText(QString(ADMIN_CHECK_OK));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment