connect() to ambiguous signals/slots: Replace static_cast with QOverload

Change-Id: I473d7a2a16509cee944a2a21b022a3f6f02cfd8d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Alessandro Portale
2019-05-27 23:28:48 +02:00
parent 1b11c4d4b6
commit 0933c20de8
34 changed files with 42 additions and 50 deletions

View File

@@ -31,7 +31,7 @@ MyMain::MyMain(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)
{
ui.setupUi(this);
connect(ui.comboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(ui.comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &MyMain::select);
}

View File

@@ -145,8 +145,7 @@ void DumpSender::sendDumpAndQuit()
connect(reply, &QNetworkReply::uploadProgress, this, &DumpSender::uploadProgress);
connect(reply, &QNetworkReply::finished, QCoreApplication::instance(), &QCoreApplication::quit);
connect(reply,
static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
connect(reply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error),
QCoreApplication::instance(), &QCoreApplication::quit);
}

View File

@@ -235,7 +235,7 @@ void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode)
} else if (auto spinBox = qobject_cast<QSpinBox *>(widget)) {
spinBox->setValue(m_value.toInt());
if (applyMode == ImmediateApply) {
connect(spinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
connect(spinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, [this, spinBox]() { setValue(spinBox->value()); });
}
} else if (auto lineEdit = qobject_cast<QLineEdit *>(widget)) {

View File

@@ -56,8 +56,7 @@ const char FORMAT_ENTIRE_FILE_FALLBACK[] = "formatEntireFileFallback";
UncrustifySettings::UncrustifySettings() :
AbstractSettings(Constants::Uncrustify::SETTINGS_NAME, ".cfg")
{
connect(&m_versionProcess,
static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
connect(&m_versionProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &UncrustifySettings::parseVersionProcessResult);
setCommand("uncrustify");

View File

@@ -87,7 +87,7 @@ public:
updateComboBox();
refresh();
connect(m_comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &CMakeKitAspectWidget::currentCMakeToolChanged);
m_manageButton->setContentsMargins(0, 0, 0, 0);

View File

@@ -118,7 +118,7 @@ ServerMode::ServerMode(const Environment &env,
connect(m_cmakeProcess.get(), &QtcProcess::started, this, [this]() { m_connectionTimer.start(); });
connect(m_cmakeProcess.get(),
static_cast<void(QtcProcess::*)(int, QProcess::ExitStatus)>(&QtcProcess::finished),
QOverload<int, QProcess::ExitStatus>::of(&QtcProcess::finished),
this, &ServerMode::handleCMakeFinished);
QString argumentString;
@@ -211,7 +211,7 @@ void ServerMode::connectToServer()
auto socket = new QLocalSocket(m_cmakeProcess.get());
connect(socket, &QLocalSocket::readyRead, this, &ServerMode::handleRawCMakeServerData);
connect(socket, static_cast<void(QLocalSocket::*)(QLocalSocket::LocalSocketError)>(&QLocalSocket::error),
connect(socket, QOverload<QLocalSocket::LocalSocketError>::of(&QLocalSocket::error),
this, [this, socket]() {
reportError(socket->errorString());
m_cmakeSocket = nullptr;

View File

@@ -498,7 +498,7 @@ void TeaLeafReader::startCMake(const QStringList &configurationArguments)
this, &TeaLeafReader::processCMakeOutput);
connect(m_cmakeProcess, &QProcess::readyReadStandardError,
this, &TeaLeafReader::processCMakeError);
connect(m_cmakeProcess, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
connect(m_cmakeProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &TeaLeafReader::cmakeFinished);
QString args;

View File

@@ -68,10 +68,8 @@ Core::Id ClangDiagnosticConfigsSelectionWidget::currentConfigId() const
void ClangDiagnosticConfigsSelectionWidget::connectToCurrentIndexChanged()
{
m_currentIndexChangedConnection
= connect(m_selectionComboBox,
static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this,
[this]() { emit currentConfigChanged(currentConfigId()); });
= connect(m_selectionComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, [this]() { emit currentConfigChanged(currentConfigId()); });
}
void ClangDiagnosticConfigsSelectionWidget::disconnectFromCurrentIndexChanged()

View File

@@ -541,7 +541,7 @@ BreakpointDialog::BreakpointDialog(unsigned int enabledParts, QWidget *parent)
verticalLayout->addWidget(m_buttonBox);
verticalLayout->setStretchFactor(groupBoxAdvanced, 10);
connect(m_comboBoxType, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
connect(m_comboBoxType, QOverload<int>::of(&QComboBox::activated),
this, &BreakpointDialog::typeChanged);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);

View File

@@ -203,7 +203,7 @@ CdbEngine::CdbEngine() :
connect(action(CreateFullBacktrace), &QAction::triggered,
this, &CdbEngine::createFullBacktrace);
connect(&m_process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &CdbEngine::processFinished);
connect(&m_process, &QProcess::errorOccurred, this, &CdbEngine::processError);
connect(&m_process, &QProcess::readyReadStandardOutput,

View File

@@ -326,7 +326,7 @@ StartApplicationDialog::StartApplicationDialog(QWidget *parent)
this, &StartApplicationDialog::updateState);
connect(d->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(d->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(d->historyComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(d->historyComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &StartApplicationDialog::historyIndexChanged);
connect(d->channelOverrideEdit, &QLineEdit::textChanged,

View File

@@ -121,7 +121,7 @@ DebuggerRunConfigWidget::DebuggerRunConfigWidget(DebuggerRunConfigurationAspect
this, &DebuggerRunConfigWidget::useQmlDebuggerClicked);
connect(m_useCppDebugger, &QAbstractButton::clicked,
this, &DebuggerRunConfigWidget::useCppDebuggerClicked);
connect(m_debugServerPort, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
connect(m_debugServerPort, QOverload<int>::of(&QSpinBox::valueChanged),
this, &DebuggerRunConfigWidget::qmlDebugServerPortChanged);
connect(m_useMultiProcess, &QAbstractButton::toggled,
this, &DebuggerRunConfigWidget::useMultiProcessToggled);

View File

@@ -145,7 +145,7 @@ public:
if (hideSwitcherUnlessNeeded)
m_engineChooser->hide();
connect(m_engineChooser, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
connect(m_engineChooser, QOverload<int>::of(&QComboBox::activated),
this, &EngineManagerPrivate::activateEngineByIndex);
}

View File

@@ -118,7 +118,7 @@ void PdbEngine::setupEngine()
QString bridge = ICore::resourcePath() + "/debugger/pdbbridge.py";
connect(&m_proc, &QProcess::errorOccurred, this, &PdbEngine::handlePdbError);
connect(&m_proc, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished),
connect(&m_proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &PdbEngine::handlePdbFinished);
connect(&m_proc, &QProcess::readyReadStandardOutput,
this, &PdbEngine::readPdbStandardOutput);

View File

@@ -245,7 +245,7 @@ public:
connect(&m_timerUpdate, &QTimer::timeout,
this, &RelativeNumbersColumn::followEditorLayout);
auto start = static_cast<void(QTimer::*)()>(&QTimer::start);
auto start = QOverload<>::of(&QTimer::start);
connect(m_editor, &QPlainTextEdit::cursorPositionChanged,
&m_timerUpdate, start);
connect(m_editor->verticalScrollBar(), &QAbstractSlider::valueChanged,

View File

@@ -81,14 +81,14 @@ QWidget *GeneralSettingsPage::widget()
updateFont(); // changes that might have happened when updating the selectors
});
connect(m_ui->styleComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(m_ui->styleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, [this]() {
updateFont();
updateFontSizeSelector();
updateFont(); // changes that might have happened when updating the selectors
});
connect(m_ui->sizeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(m_ui->sizeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &GeneralSettingsPage::updateFont);
m_homePage = LocalHelpManager::homePage();

View File

@@ -88,8 +88,6 @@ ExportDialog::ExportDialog(QWidget *parent)
, m_heightSpinBox(new QSpinBox(this))
, m_aspectRatio(1)
{
using QSpinBoxIntSignal = void (QSpinBox::*)(int);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
auto formLayout = new QFormLayout(this);
@@ -102,14 +100,14 @@ ExportDialog::ExportDialog(QWidget *parent)
auto sizeLayout = new QHBoxLayout;
m_widthSpinBox->setMinimum(exportMinimumSize);
m_widthSpinBox->setMaximum(exportMaximumSize);
connect(m_widthSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
connect(m_widthSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &ExportDialog::exportWidthChanged);
sizeLayout->addWidget(m_widthSpinBox);
//: Multiplication, as in 32x32
sizeLayout->addWidget(new QLabel(tr("x")));
m_heightSpinBox->setMinimum(exportMinimumSize);
m_heightSpinBox->setMaximum(exportMaximumSize);
connect(m_heightSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
connect(m_heightSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
this, &ExportDialog::exportHeightChanged);
sizeLayout->addWidget(m_heightSpinBox);
auto resetButton = new QToolButton(this);

View File

@@ -53,7 +53,7 @@ CreateSimulatorDialog::CreateSimulatorDialog(QWidget *parent) :
m_ui->runtimeCombo->currentIndex() > 0);
};
const auto indexChanged = static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
const auto indexChanged = QOverload<int>::of(&QComboBox::currentIndexChanged);
connect(m_ui->nameEdit, &QLineEdit::textChanged, enableOk);
connect(m_ui->runtimeCombo, indexChanged, enableOk);
connect(m_ui->deviceTypeCombo, indexChanged, [this, enableOk]() {

View File

@@ -171,7 +171,7 @@ IosBuildSettingsWidget::IosBuildSettingsWidget(IosBuildConfiguration *bc)
if (m_isDevice) {
connect(IosConfigurations::instance(), &IosConfigurations::provisioningDataChanged,
this, &IosBuildSettingsWidget::populateDevelopmentTeams);
connect(m_signEntityCombo, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(m_signEntityCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &IosBuildSettingsWidget::onSigningEntityComboIndexChanged);
connect(m_autoSignCheckbox, &QCheckBox::toggled,
this, &IosBuildSettingsWidget::configureSigningUi);

View File

@@ -332,7 +332,7 @@ void IosDeviceTypeAspect::addToConfigurationLayout(QFormLayout *layout)
updateValues();
connect(m_deviceTypeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(m_deviceTypeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &IosDeviceTypeAspect::setDeviceTypeIndex);
}

View File

@@ -60,11 +60,11 @@ NimCompilerBuildStepConfigWidget::NimCompilerBuildStepConfigWidget(NimCompilerBu
this, &NimCompilerBuildStepConfigWidget::updateUi);
// Connect UI signals
connect(m_ui->targetComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
connect(m_ui->targetComboBox, QOverload<int>::of(&QComboBox::activated),
this, &NimCompilerBuildStepConfigWidget::onTargetChanged);
connect(m_ui->additionalArgumentsLineEdit, &QLineEdit::textEdited,
this, &NimCompilerBuildStepConfigWidget::onAdditionalArgumentsTextEdited);
connect(m_ui->defaultArgumentsComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
connect(m_ui->defaultArgumentsComboBox, QOverload<int>::of(&QComboBox::activated),
this, &NimCompilerBuildStepConfigWidget::onDefaultArgumentsComboBoxIndexChanged);
updateUi();

View File

@@ -30,8 +30,8 @@ namespace Suggest {
NimSuggestServer::NimSuggestServer(QObject *parent) : QObject(parent)
{
connect(&m_process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>
(&QProcess::finished), this, &NimSuggestServer::onFinished);
connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &NimSuggestServer::onFinished);
connect(&m_process, &QProcess::started, this, &NimSuggestServer::onStarted);
connect(&m_process, &QProcess::readyReadStandardOutput, this,
&NimSuggestServer::onStandardOutputAvailable);
@@ -69,8 +69,8 @@ bool NimSuggestServer::start(const QString &executablePath,
void NimSuggestServer::kill()
{
disconnect(&m_process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>
(&QProcess::finished), this, &NimSuggestServer::onFinished);
disconnect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &NimSuggestServer::onFinished);
m_process.kill();
m_process.waitForFinished();
clearState();

View File

@@ -76,8 +76,7 @@ PerfConfigWidget::PerfConfigWidget(PerfSettings *settings, QWidget *parent) :
m_ui->sampleMode->addItem(tr("frequency (Hz)"), QLatin1String(Constants::PerfSampleFrequency));
m_ui->sampleMode->addItem(tr("event count"), QLatin1String(Constants::PerfSampleCount));
auto comboboxChangedSignal
= static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
auto comboboxChangedSignal = QOverload<int>::of(&QComboBox::currentIndexChanged);
connect(m_ui->callgraphMode, comboboxChangedSignal, this, [this](int index) {
QString mode = m_ui->callgraphMode->itemData(index).toString();
m_settings->setCallgraphMode(mode);

View File

@@ -1007,7 +1007,7 @@ void ComboBoxField::setup(JsonFieldPage *page, const QString &name)
// the selectionModel does not behave like expected and wanted - so we block signals here
// (for example there was some losing focus thing when hovering over items, ...)
selectionModel()->blockSignals(true);
QObject::connect(w, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), [w, this](int index) {
QObject::connect(w, QOverload<int>::of(&QComboBox::activated), [w, this](int index) {
w->blockSignals(true);
selectionModel()->clearSelection();

View File

@@ -376,7 +376,7 @@ public:
m_projectSelection = new QComboBox;
m_projectSelection->setModel(&m_comboBoxModel);
connect(m_projectSelection, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
connect(m_projectSelection, QOverload<int>::of(&QComboBox::activated),
this, &ProjectWindowPrivate::projectSelected, Qt::QueuedConnection);
SessionManager *sessionManager = SessionManager::instance();

View File

@@ -104,7 +104,7 @@ QWidget *ZoomAction::createWidget(QWidget *parent)
comboBox->setCurrentIndex(m_currentComboBoxIndex);
blockSignals(false);
});
connect(comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
[this, comboBox](int index) {
m_currentComboBoxIndex = index;

View File

@@ -59,7 +59,7 @@ QWidget *NumberSeriesAction::createWidget(QWidget *parent)
comboBox->setModel(m_comboBoxModel.data());
comboBox->setCurrentIndex(m_comboBoxModelIndex);
connect(comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &NumberSeriesAction::emitValueChanged);
return comboBox;

View File

@@ -39,7 +39,7 @@ ImportsWidget::ImportsWidget(QWidget *parent) :
{
setWindowTitle(tr("Import Manager"));
m_addImportComboBox = new ImportManagerComboBox(this);
connect(m_addImportComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
connect(m_addImportComboBox, QOverload<int>::of(&QComboBox::activated),
this, &ImportsWidget::addSelectedImport);
}

View File

@@ -53,7 +53,7 @@ QWidget *ComponentAction::createWidget(QWidget *parent)
comboBox->setToolTip(tr("Edit sub components defined in this file."));
comboBox->setModel(m_componentView->standardItemModel());
comboBox->setCurrentIndex(-1);
connect(comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
connect(comboBox, QOverload<int>::of(&QComboBox::activated),
this, &ComponentAction::emitCurrentComponentChanged);
connect(this, &ComponentAction::currentIndexChanged, comboBox, &QComboBox::setCurrentIndex);

View File

@@ -49,7 +49,7 @@ QnxSettingsWidget::QnxSettingsWidget(QWidget *parent) :
this, &QnxSettingsWidget::addConfiguration);
connect(m_ui->removeButton, &QAbstractButton::clicked,
this, &QnxSettingsWidget::removeConfiguration);
connect(m_ui->configsCombo, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(m_ui->configsCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &QnxSettingsWidget::updateInformation);
connect(m_ui->generateKitsCheckBox, &QAbstractButton::toggled,
this, &QnxSettingsWidget::generateKits);

View File

@@ -644,7 +644,7 @@ public:
ExampleSetModel *exampleSetModel = m_examplesModel->exampleSetModel();
exampleSetSelector->setModel(exampleSetModel);
exampleSetSelector->setCurrentIndex(exampleSetModel->selectedExampleSet());
connect(exampleSetSelector, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
connect(exampleSetSelector, QOverload<int>::of(&QComboBox::activated),
exampleSetModel, &ExampleSetModel::selectExampleSet);
connect(exampleSetModel, &ExampleSetModel::selectedExampleSetChanged,
exampleSetSelector, &QComboBox::setCurrentIndex);

View File

@@ -60,8 +60,7 @@ QWidget *CompletionSettingsPage::widget()
m_page = new Ui::CompletionSettingsPage;
m_page->setupUi(m_widget);
connect(m_page->completionTrigger,
static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
connect(m_page->completionTrigger, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &CompletionSettingsPage::onCompletionTriggerChanged);
int caseSensitivityIndex = 0;

View File

@@ -509,7 +509,7 @@ CallgrindToolPrivate::CallgrindToolPrivate()
m_searchFilter = new QLineEdit;
m_searchFilter->setPlaceholderText(CallgrindTool::tr("Filter..."));
connect(m_searchFilter, &QLineEdit::textChanged,
&m_updateTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
&m_updateTimer, QOverload<>::of(&QTimer::start));
setCostFormat(settings->costFormat());
enableCycleDetection(settings->detectCycles());

View File

@@ -85,7 +85,7 @@ ModelTestWidget::ModelTestWidget(CallgrindWidgetHandler *handler)
m_format->addItem("absolute", CostDelegate::FormatAbsolute);
m_format->addItem("relative", CostDelegate::FormatRelative);
m_format->addItem("rel. to parent", CostDelegate::FormatRelativeToParent);
connect(m_format, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
connect(m_format, QOverload<int>::of(&QComboBox::activated),
this, &ModelTestWidget::formatChanged);
h->addWidget(m_format);