diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2016-06-01 22:44:44 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2016-06-07 12:33:48 +0000 |
commit | daf715d9cae1c297ea50587c9e40c0f24bd59a07 (patch) | |
tree | c2b34cea4e9b169e1aa2c2e26872e92374af1c7c | |
parent | ddc360f424720799c26ce47d49f13929e00af2df (diff) | |
download | qbs-daf715d9cae1c297ea50587c9e40c0f24bd59a07.tar.gz |
Use Qt5-style connects
The heavy lifting was done by clazy.
Change-Id: Ibb13c517567b1b32bbda6d26225454d1b003934d
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
23 files changed, 138 insertions, 151 deletions
diff --git a/examples/collidingmice/main.cpp b/examples/collidingmice/main.cpp index 2faa4d661..0abfc6899 100644 --- a/examples/collidingmice/main.cpp +++ b/examples/collidingmice/main.cpp @@ -77,7 +77,7 @@ int main(int argc, char **argv) view.show(); QTimer timer; - QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance())); + QObject::connect(&timer, &QTimer::timeout, &scene, &QGraphicsScene::advance); timer.start(1000 / 33); return app.exec(); diff --git a/src/app/config-ui/mainwindow.cpp b/src/app/config-ui/mainwindow.cpp index 5b6319c4f..07143f96e 100644 --- a/src/app/config-ui/mainwindow.cpp +++ b/src/app/config-ui/mainwindow.cpp @@ -49,9 +49,9 @@ MainWindow::MainWindow(const QString &settingsDir, QWidget *parent) m_model = new qbs::SettingsModel(settingsDir, this); ui->treeView->setModel(m_model); ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->treeView, SIGNAL(expanded(QModelIndex)), SLOT(adjustColumns())); - connect(ui->treeView, SIGNAL(customContextMenuRequested(QPoint)), - SLOT(provideContextMenu(QPoint))); + connect(ui->treeView, &QTreeView::expanded, this, &MainWindow::adjustColumns); + connect(ui->treeView, &QWidget::customContextMenuRequested, + this, &MainWindow::provideContextMenu); adjustColumns(); QMenu * const fileMenu = menuBar()->addMenu(tr("&File")); @@ -59,20 +59,20 @@ MainWindow::MainWindow(const QString &settingsDir, QWidget *parent) QAction * const reloadAction = new QAction(tr("&Reload"), this); reloadAction->setShortcut(QKeySequence::Refresh); - connect(reloadAction, SIGNAL(triggered()), SLOT(reloadSettings())); + connect(reloadAction, &QAction::triggered, this, &MainWindow::reloadSettings); QAction * const saveAction = new QAction(tr("&Save"), this); saveAction->setShortcut(QKeySequence::Save); - connect(saveAction, SIGNAL(triggered()), SLOT(saveSettings())); + connect(saveAction, &QAction::triggered, this, &MainWindow::saveSettings); QAction * const expandAllAction = new QAction(tr("&Expand All"), this); expandAllAction->setShortcut(Qt::CTRL | Qt::Key_E); - connect(expandAllAction, SIGNAL(triggered()), SLOT(expandAll())); + connect(expandAllAction, &QAction::triggered, this, &MainWindow::expandAll); QAction * const collapseAllAction = new QAction(tr("C&ollapse All"), this); collapseAllAction->setShortcut(Qt::CTRL | Qt::Key_O); - connect(collapseAllAction, SIGNAL(triggered()), SLOT(collapseAll())); + connect(collapseAllAction, &QAction::triggered, this, &MainWindow::collapseAll); QAction * const exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcut(QKeySequence::Quit); exitAction->setMenuRole(QAction::QuitRole); - connect(exitAction, SIGNAL(triggered()), SLOT(exit())); + connect(exitAction, &QAction::triggered, this, &MainWindow::exit); fileMenu->addAction(reloadAction); fileMenu->addAction(saveAction); diff --git a/src/app/config-ui/mainwindow.h b/src/app/config-ui/mainwindow.h index 32ee143c4..2f5c6306f 100644 --- a/src/app/config-ui/mainwindow.h +++ b/src/app/config-ui/mainwindow.h @@ -49,7 +49,7 @@ public: bool eventFilter(QObject *watched, QEvent *event); -private slots: +private: void adjustColumns(); void expandAll(); void collapseAll(); @@ -58,7 +58,6 @@ private slots: void exit(); void provideContextMenu(const QPoint &pos); -private: Ui::MainWindow *ui; qbs::SettingsModel *m_model; }; diff --git a/src/app/qbs/commandlinefrontend.cpp b/src/app/qbs/commandlinefrontend.cpp index fb26bca83..96ba3d7de 100644 --- a/src/app/qbs/commandlinefrontend.cpp +++ b/src/app/qbs/commandlinefrontend.cpp @@ -44,7 +44,6 @@ #include <QDir> #include <QFile> -#include <QMetaObject> #include <QProcessEnvironment> #include <QTimer> @@ -190,7 +189,7 @@ void CommandLineFrontend::start() // experimentally found to be acceptable. // Note that this polling approach is not problematic here, since we are doing work anyway, // so there's no danger of waking up the processor for no reason. - connect(m_cancelTimer, SIGNAL(timeout()), SLOT(checkCancelStatus())); + connect(m_cancelTimer, &QTimer::timeout, this, &CommandLineFrontend::checkCancelStatus); m_cancelTimer->start(2000); } catch (const ErrorInfo &error) { qbsError() << error.toString(); @@ -549,23 +548,23 @@ void CommandLineFrontend::connectBuildJob(AbstractJob *job) if (!bjob) return; - connect(bjob, SIGNAL(reportCommandDescription(QString,QString)), - this, SLOT(handleCommandDescriptionReport(QString,QString))); - connect(bjob, SIGNAL(reportProcessResult(qbs::ProcessResult)), - this, SLOT(handleProcessResultReport(qbs::ProcessResult))); + connect(bjob, &BuildJob::reportCommandDescription, + this, &CommandLineFrontend::handleCommandDescriptionReport); + connect(bjob, &BuildJob::reportProcessResult, + this, &CommandLineFrontend::handleProcessResultReport); } void CommandLineFrontend::connectJob(AbstractJob *job) { - connect(job, SIGNAL(finished(bool,qbs::AbstractJob*)), - SLOT(handleJobFinished(bool,qbs::AbstractJob*))); - connect(job, SIGNAL(taskStarted(QString,int,qbs::AbstractJob*)), - SLOT(handleNewTaskStarted(QString,int))); - connect(job, SIGNAL(totalEffortChanged(int,qbs::AbstractJob*)), - SLOT(handleTotalEffortChanged(int))); + connect(job, &AbstractJob::finished, + this, &CommandLineFrontend::handleJobFinished); + connect(job, &AbstractJob::taskStarted, + this, &CommandLineFrontend::handleNewTaskStarted); + connect(job, &AbstractJob::totalEffortChanged, + this, &CommandLineFrontend::handleTotalEffortChanged); if (m_parser.showProgress()) { - connect(job, SIGNAL(taskProgress(int,qbs::AbstractJob*)), - SLOT(handleTaskProgress(int,qbs::AbstractJob*))); + connect(job, &AbstractJob::taskProgress, + this, &CommandLineFrontend::handleTaskProgress); } } diff --git a/src/app/qbs/commandlinefrontend.h b/src/app/qbs/commandlinefrontend.h index e4e8f531b..cf6d67085 100644 --- a/src/app/qbs/commandlinefrontend.h +++ b/src/app/qbs/commandlinefrontend.h @@ -58,9 +58,9 @@ public: ~CommandLineFrontend(); void cancel(); - -private slots: void start(); + +private: void handleCommandDescriptionReport(const QString &highlight, const QString &message); void handleJobFinished(bool success, qbs::AbstractJob *job); void handleNewTaskStarted(const QString &description, int totalEffort); @@ -69,7 +69,6 @@ private slots: void handleProcessResultReport(const qbs::ProcessResult &result); void checkCancelStatus(); -private: typedef QHash<Project, QList<ProductData> > ProductMap; ProductMap productsToUse() const; diff --git a/src/app/qbs/main.cpp b/src/app/qbs/main.cpp index 6b139bf3f..ca10b1b60 100644 --- a/src/app/qbs/main.cpp +++ b/src/app/qbs/main.cpp @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) ConsoleLogger::instance().setSettings(&settings); CommandLineFrontend clFrontend(parser, &settings); app.setCommandLineFrontend(&clFrontend); - QTimer::singleShot(0, &clFrontend, SLOT(start())); + QTimer::singleShot(0, &clFrontend, &CommandLineFrontend::start); return app.exec(); } catch (const ErrorInfo &error) { qbsError() << error.toString(); diff --git a/src/lib/corelib/api/internaljobs.cpp b/src/lib/corelib/api/internaljobs.cpp index bde4a77f4..d9737e5f2 100644 --- a/src/lib/corelib/api/internaljobs.cpp +++ b/src/lib/corelib/api/internaljobs.cpp @@ -157,21 +157,21 @@ InternalJobThreadWrapper::InternalJobThreadWrapper(InternalJob *synchronousJob, { synchronousJob->shareObserverWith(this); m_job->moveToThread(&m_thread); - connect(m_job, SIGNAL(finished(Internal::InternalJob*)), SLOT(handleFinished())); - connect(m_job, SIGNAL(newTaskStarted(QString,int,Internal::InternalJob*)), - SIGNAL(newTaskStarted(QString,int,Internal::InternalJob*))); - connect(m_job, SIGNAL(taskProgress(int,Internal::InternalJob*)), - SIGNAL(taskProgress(int,Internal::InternalJob*))); - connect(m_job, SIGNAL(totalEffortChanged(int,Internal::InternalJob*)), - SIGNAL(totalEffortChanged(int,Internal::InternalJob*))); - m_job->connect(this, SIGNAL(startRequested()), SLOT(start())); + connect(m_job, &InternalJob::finished, this, &InternalJobThreadWrapper::handleFinished); + connect(m_job, &InternalJob::newTaskStarted, + this, &InternalJob::newTaskStarted); + connect(m_job, &InternalJob::taskProgress, + this, &InternalJob::taskProgress); + connect(m_job, &InternalJob::totalEffortChanged, + this, &InternalJob::totalEffortChanged); + connect(this, &InternalJobThreadWrapper::startRequested, m_job, &InternalJob::start); } InternalJobThreadWrapper::~InternalJobThreadWrapper() { if (m_running) { QEventLoop loop; - loop.connect(m_job, SIGNAL(finished(Internal::InternalJob*)), SLOT(quit())); + connect(m_job, &InternalJob::finished, &loop, &QEventLoop::quit); cancel(); loop.exec(); } @@ -355,15 +355,15 @@ void InternalBuildJob::build(const TopLevelProjectPtr &project, QThread * const executorThread = new QThread(this); m_executor->moveToThread(executorThread); - connect(m_executor, SIGNAL(reportCommandDescription(QString,QString)), - this, SIGNAL(reportCommandDescription(QString,QString))); - connect(m_executor, SIGNAL(reportProcessResult(qbs::ProcessResult)), - this, SIGNAL(reportProcessResult(qbs::ProcessResult))); - - connect(executorThread, SIGNAL(started()), m_executor, SLOT(build())); - connect(m_executor, SIGNAL(finished()), SLOT(handleFinished())); - connect(m_executor, SIGNAL(destroyed()), executorThread, SLOT(quit())); - connect(executorThread, SIGNAL(finished()), this, SLOT(emitFinished())); + connect(m_executor, &Executor::reportCommandDescription, + this, &BuildGraphTouchingJob::reportCommandDescription); + connect(m_executor, &Executor::reportProcessResult, + this, &BuildGraphTouchingJob::reportProcessResult); + + connect(executorThread, &QThread::started, m_executor, &Executor::build); + connect(m_executor, &Executor::finished, this, &InternalBuildJob::handleFinished); + connect(m_executor, &QObject::destroyed, executorThread, &QThread::quit); + connect(executorThread, &QThread::finished, this, &InternalBuildJob::emitFinished); executorThread->start(); } diff --git a/src/lib/corelib/api/internaljobs.h b/src/lib/corelib/api/internaljobs.h index b1bda46b4..ccae965d8 100644 --- a/src/lib/corelib/api/internaljobs.h +++ b/src/lib/corelib/api/internaljobs.h @@ -62,6 +62,7 @@ public: ~InternalJob(); void cancel(); + virtual void start() {} ErrorInfo error() const { return m_error; } void setError(const ErrorInfo &error) { m_error = error; } @@ -98,16 +99,15 @@ public: InternalJobThreadWrapper(InternalJob *synchronousJob, QObject *parent = 0); ~InternalJobThreadWrapper(); - void start(); + void start() override; InternalJob *synchronousJob() const { return m_job; } signals: void startRequested(); -private slots: +private: void handleFinished(); -private: QThread m_thread; InternalJob *m_job; bool m_running; @@ -125,10 +125,8 @@ public: TopLevelProjectPtr project() const; -private slots: - void start(); - private: + void start() override; void resolveProjectFromScratch(Internal::ScriptEngine *engine); void resolveBuildDataFromScratch(const RulesEvaluationContextPtr &evalContext); BuildGraphLoadResult restoreProject(const RulesEvaluationContextPtr &evalContext); @@ -175,11 +173,10 @@ public: void build(const TopLevelProjectPtr &project, const QList<ResolvedProductPtr> &products, const BuildOptions &buildOptions); -private slots: +private: void handleFinished(); void emitFinished(); -private: Executor *m_executor; }; @@ -193,10 +190,9 @@ public: void init(const TopLevelProjectPtr &project, const QList<ResolvedProductPtr> &products, const CleanOptions &options); -private slots: - void start(); - private: + void start() override; + CleanOptions m_options; }; @@ -211,10 +207,9 @@ public: void init(const TopLevelProjectPtr &project, const QList<ResolvedProductPtr> &products, const InstallOptions &options); -private slots: - void start(); - private: + void start() override; + TopLevelProjectPtr m_project; QList<ResolvedProductPtr> m_products; InstallOptions m_options; diff --git a/src/lib/corelib/api/jobs.cpp b/src/lib/corelib/api/jobs.cpp index d959e1b5d..7e7844d36 100644 --- a/src/lib/corelib/api/jobs.cpp +++ b/src/lib/corelib/api/jobs.cpp @@ -34,7 +34,7 @@ #include <language/language.h> #include <tools/qbsassert.h> -#include <QMetaObject> +#include <QTimer> namespace qbs { using namespace Internal; @@ -106,13 +106,13 @@ AbstractJob::AbstractJob(InternalJob *internalJob, QObject *parent) : QObject(parent), m_internalJob(internalJob) { m_internalJob->setParent(this); - connect(m_internalJob, SIGNAL(newTaskStarted(QString,int,Internal::InternalJob*)), - SLOT(handleTaskStarted(QString,int)), Qt::QueuedConnection); - connect(m_internalJob, SIGNAL(totalEffortChanged(int,Internal::InternalJob*)), - SLOT(handleTotalEffortChanged(int))); - connect(m_internalJob, SIGNAL(taskProgress(int,Internal::InternalJob*)), - SLOT(handleTaskProgress(int)), Qt::QueuedConnection); - connect(m_internalJob, SIGNAL(finished(Internal::InternalJob*)), SLOT(handleFinished())); + connect(m_internalJob, &InternalJob::newTaskStarted, + this, &AbstractJob::handleTaskStarted, Qt::QueuedConnection); + connect(m_internalJob, &InternalJob::totalEffortChanged, + this, &AbstractJob::handleTotalEffortChanged); + connect(m_internalJob, &InternalJob::taskProgress, + this, &AbstractJob::handleTaskProgress, Qt::QueuedConnection); + connect(m_internalJob, &InternalJob::finished, this, &AbstractJob::handleFinished); m_state = StateRunning; } @@ -122,8 +122,7 @@ bool AbstractJob::lockProject(const TopLevelProjectPtr &project) // synchronously. if (project->locked) { internalJob()->setError(tr("Cannot start a job while another one is in progress.")); - QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection, Q_ARG(bool, false), - Q_ARG(qbs::AbstractJob *, this)); + QTimer::singleShot(0, this, [this] { emit finished(false, this); }); return false; } project->locked = true; @@ -293,10 +292,10 @@ BuildJob::BuildJob(const Logger &logger, QObject *parent) : AbstractJob(new InternalBuildJob(logger), parent) { InternalBuildJob *job = static_cast<InternalBuildJob *>(internalJob()); - connect(job, SIGNAL(reportCommandDescription(QString,QString)), - this, SIGNAL(reportCommandDescription(QString,QString))); - connect(job, SIGNAL(reportProcessResult(qbs::ProcessResult)), - this, SIGNAL(reportProcessResult(qbs::ProcessResult))); + connect(job, &BuildGraphTouchingJob::reportCommandDescription, + this, &BuildJob::reportCommandDescription); + connect(job, &BuildGraphTouchingJob::reportProcessResult, + this, &BuildJob::reportProcessResult); } void BuildJob::build(const TopLevelProjectPtr &project, const QList<ResolvedProductPtr> &products, diff --git a/src/lib/corelib/api/jobs.h b/src/lib/corelib/api/jobs.h index 0a25e106c..e582775c9 100644 --- a/src/lib/corelib/api/jobs.h +++ b/src/lib/corelib/api/jobs.h @@ -79,13 +79,12 @@ signals: void taskProgress(int newProgressValue, qbs::AbstractJob *job); void finished(bool success, qbs::AbstractJob *job); -private slots: +private: void handleTaskStarted(const QString &description, int maximumProgressValue); void handleTotalEffortChanged(int totalEffort); void handleTaskProgress(int newProgressValue); void handleFinished(); -private: void unlockProject(); virtual void finish() { } diff --git a/src/lib/corelib/buildgraph/abstractcommandexecutor.h b/src/lib/corelib/buildgraph/abstractcommandexecutor.h index 5c60886a6..f7af54d61 100644 --- a/src/lib/corelib/buildgraph/abstractcommandexecutor.h +++ b/src/lib/corelib/buildgraph/abstractcommandexecutor.h @@ -57,7 +57,6 @@ public: virtual void cancel() = 0; -public slots: void start(Transformer *transformer, const AbstractCommand *cmd); signals: diff --git a/src/lib/corelib/buildgraph/executor.cpp b/src/lib/corelib/buildgraph/executor.cpp index 853d1f44c..bd4fec099 100644 --- a/src/lib/corelib/buildgraph/executor.cpp +++ b/src/lib/corelib/buildgraph/executor.cpp @@ -82,7 +82,7 @@ Executor::Executor(const Logger &logger, QObject *parent) m_inputArtifactScanContext = new InputArtifactScannerContext(&m_scanResultCache); m_cancelationTimer->setSingleShot(false); m_cancelationTimer->setInterval(1000); - connect(m_cancelationTimer, SIGNAL(timeout()), SLOT(checkForCancellation())); + connect(m_cancelationTimer, &QTimer::timeout, this, &Executor::checkForCancellation); } Executor::~Executor() @@ -207,7 +207,7 @@ void Executor::doBuild() if (m_productsToBuild.isEmpty()) { m_logger.qbsTrace() << "No products to build, finishing."; - QTimer::singleShot(0, this, SLOT(finish())); // Don't call back on the caller. + QTimer::singleShot(0, this, &Executor::finish); // Don't call back on the caller. return; } @@ -236,7 +236,7 @@ void Executor::doBuild() initLeaves(); if (!scheduleJobs()) { m_logger.qbsTrace() << "Nothing to do at all, finishing."; - QTimer::singleShot(0, this, SLOT(finish())); // Don't call back on the caller. + QTimer::singleShot(0, this, &Executor::finish); // Don't call back on the caller. } if (m_progressObserver) m_cancelationTimer->start(); @@ -685,12 +685,12 @@ void Executor::addExecutorJobs() job->setDryRun(m_buildOptions.dryRun()); job->setEchoMode(m_buildOptions.echoMode()); m_availableJobs.append(job); - connect(job, SIGNAL(reportCommandDescription(QString,QString)), - this, SIGNAL(reportCommandDescription(QString,QString)), Qt::QueuedConnection); - connect(job, SIGNAL(reportProcessResult(qbs::ProcessResult)), - this, SIGNAL(reportProcessResult(qbs::ProcessResult)), Qt::QueuedConnection); - connect(job, SIGNAL(finished(qbs::ErrorInfo)), - this, SLOT(onJobFinished(qbs::ErrorInfo)), Qt::QueuedConnection); + connect(job, &ExecutorJob::reportCommandDescription, + this, &Executor::reportCommandDescription, Qt::QueuedConnection); + connect(job, &ExecutorJob::reportProcessResult, + this, &Executor::reportProcessResult, Qt::QueuedConnection); + connect(job, &ExecutorJob::finished, + this, &Executor::onJobFinished, Qt::QueuedConnection); } } @@ -919,8 +919,7 @@ void Executor::onJobFinished(const qbs::ErrorInfo &err) if (m_evalContext->isActive()) { m_logger.qbsDebug() << "Executor job finished while rule execution is pausing. " "Delaying slot execution."; - QMetaObject::invokeMethod(job, "finished", Qt::QueuedConnection, - Q_ARG(qbs::ErrorInfo, err)); + QTimer::singleShot(0, job, [job, err] { job->finished(err); }); return; } diff --git a/src/lib/corelib/buildgraph/executor.h b/src/lib/corelib/buildgraph/executor.h index d626cca3d..a923e78e9 100644 --- a/src/lib/corelib/buildgraph/executor.h +++ b/src/lib/corelib/buildgraph/executor.h @@ -63,10 +63,9 @@ class Executor : public QObject, private BuildGraphVisitor { Q_OBJECT -public slots: +public: void build(); -public: Executor(const Logger &logger, QObject *parent = 0); ~Executor(); @@ -83,12 +82,11 @@ signals: void finished(); -private slots: +private: void onJobFinished(const qbs::ErrorInfo &err); void finish(); void checkForCancellation(); -private: // BuildGraphVisitor implementation bool visit(Artifact *artifact); bool visit(RuleNode *ruleNode); diff --git a/src/lib/corelib/buildgraph/executorjob.cpp b/src/lib/corelib/buildgraph/executorjob.cpp index 09c68f25d..9c1b30ede 100644 --- a/src/lib/corelib/buildgraph/executorjob.cpp +++ b/src/lib/corelib/buildgraph/executorjob.cpp @@ -49,16 +49,16 @@ ExecutorJob::ExecutorJob(const Logger &logger, QObject *parent) , m_processCommandExecutor(new ProcessCommandExecutor(logger, this)) , m_jsCommandExecutor(new JsCommandExecutor(logger, this)) { - connect(m_processCommandExecutor, SIGNAL(reportCommandDescription(QString,QString)), - this, SIGNAL(reportCommandDescription(QString,QString))); - connect(m_processCommandExecutor, SIGNAL(reportProcessResult(qbs::ProcessResult)), - this, SIGNAL(reportProcessResult(qbs::ProcessResult))); - connect(m_processCommandExecutor, SIGNAL(finished(qbs::ErrorInfo)), - this, SLOT(onCommandFinished(qbs::ErrorInfo))); - connect(m_jsCommandExecutor, SIGNAL(reportCommandDescription(QString,QString)), - this, SIGNAL(reportCommandDescription(QString,QString))); - connect(m_jsCommandExecutor, SIGNAL(finished(qbs::ErrorInfo)), - this, SLOT(onCommandFinished(qbs::ErrorInfo))); + connect(m_processCommandExecutor, &AbstractCommandExecutor::reportCommandDescription, + this, &ExecutorJob::reportCommandDescription); + connect(m_processCommandExecutor, &ProcessCommandExecutor::reportProcessResult, + this, &ExecutorJob::reportProcessResult); + connect(m_processCommandExecutor, &AbstractCommandExecutor::finished, + this, &ExecutorJob::onCommandFinished); + connect(m_jsCommandExecutor, &AbstractCommandExecutor::reportCommandDescription, + this, &ExecutorJob::reportCommandDescription); + connect(m_jsCommandExecutor, &AbstractCommandExecutor::finished, + this, &ExecutorJob::onCommandFinished); reset(); } diff --git a/src/lib/corelib/buildgraph/executorjob.h b/src/lib/corelib/buildgraph/executorjob.h index 95b73098c..36c144e62 100644 --- a/src/lib/corelib/buildgraph/executorjob.h +++ b/src/lib/corelib/buildgraph/executorjob.h @@ -68,11 +68,10 @@ signals: void reportProcessResult(const qbs::ProcessResult &result); void finished(const qbs::ErrorInfo &error = ErrorInfo()); // !hasError() <=> command successful -private slots: +private: void runNextCommand(); void onCommandFinished(const qbs::ErrorInfo &err); -private: void setFinished(); void reset(); diff --git a/src/lib/corelib/buildgraph/jscommandexecutor.cpp b/src/lib/corelib/buildgraph/jscommandexecutor.cpp index 077b15969..92be1e46e 100644 --- a/src/lib/corelib/buildgraph/jscommandexecutor.cpp +++ b/src/lib/corelib/buildgraph/jscommandexecutor.cpp @@ -44,7 +44,6 @@ #include <tools/qbsassert.h> #include <QEventLoop> -#include <QMetaObject> #include <QThread> #include <QTimer> @@ -73,7 +72,7 @@ public: return m_result; } - Q_INVOKABLE void cancel() + void cancel() { QBS_ASSERT(m_scriptEngine, return); m_scriptEngine->abortEvaluation(); @@ -82,7 +81,7 @@ public: signals: void finished(); -public slots: +public: void start(const JavaScriptCommand *cmd, Transformer *transformer) { try { @@ -153,9 +152,10 @@ JsCommandExecutor::JsCommandExecutor(const Logger &logger, QObject *parent) , m_running(false) { m_objectInThread->moveToThread(m_thread); - connect(m_objectInThread, SIGNAL(finished()), this, SLOT(onJavaScriptCommandFinished())); - connect(this, SIGNAL(startRequested(const JavaScriptCommand*,Transformer*)), - m_objectInThread, SLOT(start(const JavaScriptCommand*,Transformer*))); + connect(m_objectInThread, &JsCommandExecutorThreadObject::finished, + this, &JsCommandExecutor::onJavaScriptCommandFinished); + connect(this, &JsCommandExecutor::startRequested, + m_objectInThread, &JsCommandExecutorThreadObject::start); } JsCommandExecutor::~JsCommandExecutor() @@ -183,7 +183,7 @@ void JsCommandExecutor::waitForFinished() if (!m_running) return; QEventLoop loop; - loop.connect(m_objectInThread, SIGNAL(finished()), SLOT(quit())); + connect(m_objectInThread, &JsCommandExecutorThreadObject::finished, &loop, &QEventLoop::quit); loop.exec(); } @@ -193,7 +193,7 @@ void JsCommandExecutor::doStart() m_thread->start(); if (dryRun() && !command()->ignoreDryRun()) { - QTimer::singleShot(0, this, SIGNAL(finished())); // Don't call back on the caller. + QTimer::singleShot(0, this, [this] { emit finished(); }); // Don't call back on the caller. return; } @@ -204,7 +204,7 @@ void JsCommandExecutor::doStart() void JsCommandExecutor::cancel() { if (!dryRun()) - QMetaObject::invokeMethod(m_objectInThread, "cancel", Qt::QueuedConnection); + QTimer::singleShot(0, m_objectInThread, [this] { m_objectInThread->cancel(); }); } void JsCommandExecutor::onJavaScriptCommandFinished() diff --git a/src/lib/corelib/buildgraph/jscommandexecutor.h b/src/lib/corelib/buildgraph/jscommandexecutor.h index 47a3e34d3..78b24042e 100644 --- a/src/lib/corelib/buildgraph/jscommandexecutor.h +++ b/src/lib/corelib/buildgraph/jscommandexecutor.h @@ -52,10 +52,9 @@ public: signals: void startRequested(const JavaScriptCommand *cmd, Transformer *transformer); -private slots: +private: void onJavaScriptCommandFinished(); -private: void doReportCommandDescription(); void doStart(); void cancel(); diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.cpp b/src/lib/corelib/buildgraph/processcommandexecutor.cpp index 6f36838d6..dc95ac4d8 100644 --- a/src/lib/corelib/buildgraph/processcommandexecutor.cpp +++ b/src/lib/corelib/buildgraph/processcommandexecutor.cpp @@ -61,8 +61,10 @@ namespace Internal { ProcessCommandExecutor::ProcessCommandExecutor(const Logger &logger, QObject *parent) : AbstractCommandExecutor(logger, parent) { - connect(&m_process, SIGNAL(error(QProcess::ProcessError)), SLOT(onProcessError())); - connect(&m_process, SIGNAL(finished(int)), SLOT(onProcessFinished())); + connect(&m_process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error), + this, &ProcessCommandExecutor::onProcessError); + connect(&m_process, static_cast<void (QProcess::*)(int)>(&QProcess::finished), + this, &ProcessCommandExecutor::onProcessFinished); } void ProcessCommandExecutor::doSetup() @@ -94,7 +96,7 @@ void ProcessCommandExecutor::doStart() QStringList arguments = m_arguments; if (dryRun() && !cmd->ignoreDryRun()) { - QTimer::singleShot(0, this, SIGNAL(finished())); // Don't call back on the caller. + QTimer::singleShot(0, this, [this] { emit finished(); }); // Don't call back on the caller. return; } @@ -155,7 +157,7 @@ void ProcessCommandExecutor::doStart() void ProcessCommandExecutor::cancel() { // We don't want this command to be reported as failing, since we explicitly terminated it. - disconnect(this, SIGNAL(reportProcessResult(qbs::ProcessResult)), 0, 0); + disconnect(this, &ProcessCommandExecutor::reportProcessResult, 0, 0); m_process.terminate(); if (!m_process.waitForFinished(1000)) diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.h b/src/lib/corelib/buildgraph/processcommandexecutor.h index 1b7a35575..d2976b007 100644 --- a/src/lib/corelib/buildgraph/processcommandexecutor.h +++ b/src/lib/corelib/buildgraph/processcommandexecutor.h @@ -56,11 +56,10 @@ public: signals: void reportProcessResult(const qbs::ProcessResult &result); -private slots: +private: void onProcessError(); void onProcessFinished(); -private: void doSetup(); void doReportCommandDescription(); void doStart(); diff --git a/src/lib/corelib/language/scriptengine.cpp b/src/lib/corelib/language/scriptengine.cpp index 4a1e1280b..4897faac5 100644 --- a/src/lib/corelib/language/scriptengine.cpp +++ b/src/lib/corelib/language/scriptengine.cpp @@ -50,6 +50,7 @@ #include <QScriptValueIterator> #include <QSet> #include <QTextStream> +#include <QTimer> namespace qbs { namespace Internal { @@ -416,7 +417,7 @@ QScriptValueList ScriptEngine::argumentList(const QStringList &argumentNames, void ScriptEngine::cancel() { - QMetaObject::invokeMethod(this, "abort", Qt::QueuedConnection); + QTimer::singleShot(0, this, [this] { abort(); }); } void ScriptEngine::abort() diff --git a/src/lib/corelib/language/scriptengine.h b/src/lib/corelib/language/scriptengine.h index 76c699fe2..16d51f032 100644 --- a/src/lib/corelib/language/scriptengine.h +++ b/src/lib/corelib/language/scriptengine.h @@ -126,7 +126,7 @@ public: void cancel(); private: - Q_INVOKABLE void abort(); + void abort(); void installQbsBuiltins(); void extendJavaScriptBuiltins(); diff --git a/tests/auto/api/tst_api.cpp b/tests/auto/api/tst_api.cpp index 33a09dd3b..79667ab2e 100644 --- a/tests/auto/api/tst_api.cpp +++ b/tests/auto/api/tst_api.cpp @@ -77,7 +77,6 @@ class BuildDescriptionReceiver : public QObject public: QString descriptions; -private slots: void handleDescription(const QString &, const QString &description) { descriptions += description; } @@ -90,7 +89,6 @@ public: QString output; QVector<qbs::ProcessResult> results; -private slots: void handleProcessResult(const qbs::ProcessResult &result) { results << result; output += result.stdErr().join(QLatin1Char('\n')); @@ -104,7 +102,6 @@ class TaskReceiver : public QObject public: QString taskDescriptions; -private slots: void handleTaskStart(const QString &task) { taskDescriptions += task; } }; @@ -123,10 +120,10 @@ static bool waitForFinished(qbs::AbstractJob *job, int timeout = 0) if (job->state() == qbs::AbstractJob::StateFinished) return true; QEventLoop loop; - QObject::connect(job, SIGNAL(finished(bool,qbs::AbstractJob*)), &loop, SLOT(quit())); + QObject::connect(job, &qbs::AbstractJob::finished, &loop, &QEventLoop::quit); if (timeout > 0) { QTimer timer; - QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); timer.setSingleShot(true); timer.start(timeout); loop.exec(); @@ -385,8 +382,8 @@ void TestApi::buildSingleFile() m_logSink->setLogLevel(qbs::LoggerMaxLevel); QScopedPointer<qbs::BuildJob> buildJob(project.buildAllProducts(options)); BuildDescriptionReceiver receiver; - connect(buildJob.data(), SIGNAL(reportCommandDescription(QString,QString)), &receiver, - SLOT(handleDescription(QString,QString))); + connect(buildJob.data(), &qbs::BuildJob::reportCommandDescription, &receiver, + &BuildDescriptionReceiver::handleDescription); waitForFinished(buildJob.data()); QVERIFY2(!buildJob->error().hasError(), qPrintable(buildJob->error().toString())); QCOMPARE(receiver.descriptions.count("compiling"), 1); @@ -727,8 +724,8 @@ void TestApi::changeContent() BuildDescriptionReceiver rcvr; QScopedPointer<qbs::BuildJob> buildJob(project.buildAllProducts(buildOptions, defaultProducts(), this)); - connect(buildJob.data(), SIGNAL(reportCommandDescription(QString,QString)), &rcvr, - SLOT(handleDescription(QString,QString))); + connect(buildJob.data(), &qbs::BuildJob::reportCommandDescription, + &rcvr, &BuildDescriptionReceiver::handleDescription); waitForFinished(buildJob.data()); QVERIFY2(!buildJob->error().hasError(), qPrintable(buildJob->error().toString())); QVERIFY(rcvr.descriptions.contains("compiling file.cpp")); @@ -757,8 +754,8 @@ void TestApi::changeContent() // Now try building again and check if the newly resolved product behaves the same way. buildJob.reset(project.buildAllProducts(buildOptions, defaultProducts(), this)); - connect(buildJob.data(), SIGNAL(reportCommandDescription(QString,QString)), &rcvr, - SLOT(handleDescription(QString,QString))); + connect(buildJob.data(), &qbs::BuildJob::reportCommandDescription, + &rcvr, &BuildDescriptionReceiver::handleDescription); waitForFinished(buildJob.data()); QVERIFY2(!buildJob->error().hasError(), qPrintable(buildJob->error().toString())); QVERIFY(rcvr.descriptions.contains("compiling file.cpp")); @@ -796,8 +793,8 @@ void TestApi::changeContent() projectData = project.projectData(); rcvr.descriptions.clear(); buildJob.reset(project.buildAllProducts(buildOptions, defaultProducts(), this)); - connect(buildJob.data(), SIGNAL(reportCommandDescription(QString,QString)), &rcvr, - SLOT(handleDescription(QString,QString))); + connect(buildJob.data(), &qbs::BuildJob::reportCommandDescription, + &rcvr, &BuildDescriptionReceiver::handleDescription); waitForFinished(buildJob.data()); QVERIFY2(!buildJob->error().hasError(), qPrintable(buildJob->error().toString())); QVERIFY(rcvr.descriptions.contains("compiling main.cpp")); @@ -1138,7 +1135,7 @@ void TestApi::infiniteLoopBuilding() QVERIFY2(!setupJob->error().hasError(), qPrintable(setupJob->error().toString())); qbs::Project project = setupJob->project(); const QScopedPointer<qbs::BuildJob> buildJob(project.buildAllProducts(qbs::BuildOptions())); - QTimer::singleShot(1000, buildJob.data(), SLOT(cancel())); + QTimer::singleShot(1000, buildJob.data(), &qbs::AbstractJob::cancel); QVERIFY(waitForFinished(buildJob.data(), 600000)); } @@ -1155,7 +1152,7 @@ void TestApi::infiniteLoopResolving() = defaultSetupParameters("infinite-loop-resolving/project.qbs"); QScopedPointer<qbs::SetupProjectJob> setupJob(qbs::Project().setupProject(setupParams, m_logSink, 0)); - QTimer::singleShot(1000, setupJob.data(), SLOT(cancel())); + QTimer::singleShot(1000, setupJob.data(), &qbs::AbstractJob::cancel); QVERIFY(waitForFinished(setupJob.data(), 600000)); QVERIFY2(setupJob->error().toString().toLower().contains("cancel"), qPrintable(setupJob->error().toString())); @@ -1957,9 +1954,10 @@ void TestApi::uic() } -qbs::ErrorInfo TestApi::doBuildProject(const QString &projectFilePath, - QObject *buildDescriptionReceiver, QObject *procResultReceiver, QObject *taskReceiver, - const qbs::BuildOptions &options, const QVariantMap overriddenValues) +qbs::ErrorInfo TestApi::doBuildProject( + const QString &projectFilePath, BuildDescriptionReceiver *buildDescriptionReceiver, + ProcessResultReceiver *procResultReceiver, TaskReceiver *taskReceiver, + const qbs::BuildOptions &options, const QVariantMap overriddenValues) { qbs::SetupProjectParameters params = defaultSetupParameters(projectFilePath); params.setOverriddenValues(overriddenValues); @@ -1967,20 +1965,20 @@ qbs::ErrorInfo TestApi::doBuildProject(const QString &projectFilePath, const QScopedPointer<qbs::SetupProjectJob> setupJob(qbs::Project().setupProject(params, m_logSink, 0)); if (taskReceiver) { - connect(setupJob.data(), SIGNAL(taskStarted(QString,int,qbs::AbstractJob*)), taskReceiver, - SLOT(handleTaskStart(QString))); + connect(setupJob.data(), &qbs::AbstractJob::taskStarted, + taskReceiver, &TaskReceiver::handleTaskStart); } waitForFinished(setupJob.data()); if (setupJob->error().hasError()) return setupJob->error(); const QScopedPointer<qbs::BuildJob> buildJob(setupJob->project().buildAllProducts(options)); if (buildDescriptionReceiver) { - connect(buildJob.data(), SIGNAL(reportCommandDescription(QString,QString)), - buildDescriptionReceiver, SLOT(handleDescription(QString,QString))); + connect(buildJob.data(), &qbs::BuildJob::reportCommandDescription, + buildDescriptionReceiver, &BuildDescriptionReceiver::handleDescription); } if (procResultReceiver) { - connect(buildJob.data(), SIGNAL(reportProcessResult(qbs::ProcessResult)), - procResultReceiver, SLOT(handleProcessResult(qbs::ProcessResult))); + connect(buildJob.data(), &qbs::BuildJob::reportProcessResult, + procResultReceiver, &ProcessResultReceiver::handleProcessResult); } waitForFinished(buildJob.data()); return buildJob->error(); diff --git a/tests/auto/api/tst_api.h b/tests/auto/api/tst_api.h index 7738f7a97..eb88ea35a 100644 --- a/tests/auto/api/tst_api.h +++ b/tests/auto/api/tst_api.h @@ -41,7 +41,10 @@ class ErrorInfo; class SetupProjectParameters; } +class BuildDescriptionReceiver; class LogSink; +class ProcessResultReceiver; +class TaskReceiver; class TestApi : public QObject { @@ -130,9 +133,9 @@ private slots: private: qbs::SetupProjectParameters defaultSetupParameters(const QString &projectFilePath) const; qbs::ErrorInfo doBuildProject(const QString &projectFilePath, - QObject *buildDescriptionReceiver = 0, - QObject *procResultReceiver = 0, - QObject *taskReceiver = 0, + BuildDescriptionReceiver *buildDescriptionReceiver = 0, + ProcessResultReceiver *procResultReceiver = 0, + TaskReceiver *taskReceiver = 0, const qbs::BuildOptions &options = qbs::BuildOptions(), const QVariantMap overriddenValues = QVariantMap()); |