Hi, can you please help me. I have the problem that when i call action from action sometimes it’s failed with error code 4. Can you please explain me the reason and tell me what i can do in this situation. I don’t want to change the arch of the app.
Here is some code. First action caller. Just button which calls action:
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QDebug>
#include <KAuth>
#include <QPushButton>
using namespace KAuth;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->pushButton, &QPushButton::pressed, [=]() {
qInfo() << "Clicked";
static const auto actionName = QStringLiteral("test.helper.change");
static const auto actionHelperId = QStringLiteral("test.helper");
KAuth::Action action(actionName);
action.setHelperId(actionHelperId);
action.setArguments({});
auto job = action.execute();
if (!job->exec()) {
qInfo() << "Error 1 lvl action";
qInfo() << job->errorString();
qInfo() << job->errorText();
qInfo() << "Erorr:" << job->error();
qInfo() << "Action:" << job->action().name();
} else {
qInfo() << "No erorr at 1 lvl action";
}
});
}
MainWindow::~MainWindow()
{
delete ui;
}
First helper code:
#include <QObject>
#include <KAuth>
#include <QDebug>
using namespace KAuth;
class Helper : public QObject
{
Q_OBJECT
public slots:
KAuth::ActionReply change(const QVariantMap &args);
};
KAuth::ActionReply Helper::change(const QVariantMap &args)
{
qInfo() << "First lvl action start";
static const auto actionName = QStringLiteral("kcm.policycomplexity.change");
static const auto actionHelperId = QStringLiteral("kcm.policycomplexity");
KAuth::Action action(actionName);
action.setHelperId(actionHelperId);
action.setArguments({});
auto job = action.execute();
if (!job->exec()) {
qInfo() << "Error 2 lvl action";
return ActionReply::HelperErrorReply();
}
qInfo() << "First lvl action end";
return ActionReply::SuccessReply();
}
KAUTH_HELPER_MAIN("test.helper", Helper)
#include "test_helper.moc"
Second helper code:
#include <QObject>
#include <KAuth/ActionReply>
#include <KAuth/HelperSupport>
#include "config.h"
#include <QDebug>
namespace PasswordComplexityPolicy {
class Helper : public QObject
{
Q_OBJECT
public slots:
KAuth::ActionReply change(const QVariantMap &args);
};
namespace {
KAuth::ActionReply errorReply(const QString &errorDesc)
{
auto reply = KAuth::ActionReply::HelperErrorReply();
reply.setErrorDescription(errorDesc);
return reply;
}
} // namespace
KAuth::ActionReply Helper::change(const QVariantMap &args)
{
qInfo() << "2 lvl action start";
qInfo() << "2 lvl action end";
return KAuth::ActionReply::SuccessReply();
}
}
KAUTH_HELPER_MAIN("kcm.policycomplexity", PasswordComplexityPolicy::Helper)
#include "helper.moc"