Commit c93c3dfb authored by Ahmad Samir's avatar Ahmad Samir Committed by Ingo Klöcker
Browse files

Alternative way to make signals private

By using QPrivateSignal as an extra arg to ensure users and sub-classes
can't emit them, c.f.:
https://woboq.com/blog/how-qt-signals-slots-work-part2-qt5.html

Note that this is needed to make it compile at all with the PMF signal/slot
syntax, if it's a private method we can't call it in the lambda.
parent 208e5a0a
Pipeline #174313 passed with stage
in 3 minutes and 27 seconds
......@@ -115,8 +115,8 @@ ChecksumCreateFilesCommand::ChecksumCreateFilesCommand(const QStringList &files,
void ChecksumCreateFilesCommand::Private::init()
{
controller.setExecutionContext(shared_qq);
connect(&controller, SIGNAL(done()), q, SLOT(slotControllerDone()));
connect(&controller, SIGNAL(error(int,QString)), q, SLOT(slotControllerError(int,QString)));
connect(&controller, &Crypto::Controller::done, q, [this]() { slotControllerDone(); });
connect(&controller, &Crypto::Controller::error, q, [this](int err, const QString &details) { slotControllerError(err,details); });
}
ChecksumCreateFilesCommand::~ChecksumCreateFilesCommand()
......
......@@ -69,11 +69,11 @@ void Controller::setLastError(int err, const QString &msg)
void Controller::emitDoneOrError()
{
if (d->lastError) {
Q_EMIT error(d->lastError, d->lastErrorString);
Q_EMIT error(d->lastError, d->lastErrorString, QPrivateSignal{});
d->lastError = 0;
d->lastErrorString = QString();
} else {
done();
Q_EMIT done(QPrivateSignal{});
}
}
......@@ -47,14 +47,23 @@ protected Q_SLOTS:
void taskDone(const std::shared_ptr<const Kleo::Crypto::Task::Result> &);
Q_SIGNALS:
#ifndef Q_MOC_RUN
# ifndef DOXYGEN_SHOULD_SKIP_THIS
private: // don't tell moc or doxygen, but those signals are in fact private
# endif
#endif
void error(int err, const QString &details);
void done();
/**
* Private signal, you can connect to it, but derived classes cannot emit it.
*/
void error(int err, const QString &details
# ifndef DOXYGEN_SHOULD_SKIP_THIS
, QPrivateSignal
#endif
);
/**
* Private signal, you can connect to it, but derived classes cannot emit it.
*/
void done(
# ifndef DOXYGEN_SHOULD_SKIP_THIS
QPrivateSignal
#endif
);
private:
class Private;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment