Pass this context object to the connect()

Otherwise when "this" instance
gets deleted and the sender still exists, the lambda
expression is still invoked for the deleted object.

Task-number: QTCREATORBUG-20223
Change-Id: Ifd5c9e6ce1fe7fde71698c6683cdfcd7566e8d35
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2018-04-06 15:57:30 +02:00
parent 18ad5653d5
commit e806ea40cc
4 changed files with 14 additions and 14 deletions

View File

@@ -44,7 +44,7 @@ DescriptionWidgetWatcher::DescriptionWidgetWatcher(DiffEditorController *control
m_widgets.append(widget);
}
connect(EditorManager::instance(), &EditorManager::editorOpened,
connect(EditorManager::instance(), &EditorManager::editorOpened, this,
[this](IEditor *editor) {
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) {
m_widgets.append(widget);
@@ -52,7 +52,7 @@ DescriptionWidgetWatcher::DescriptionWidgetWatcher(DiffEditorController *control
}
});
connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
connect(EditorManager::instance(), &EditorManager::editorAboutToClose, this,
[this](IEditor *editor) {
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) {
emit descriptionWidgetRemoved(widget);

View File

@@ -227,7 +227,7 @@ void DiffEditorWidgetController::addCodePasterAction(QMenu *menu, int fileIndex,
if (ExtensionSystem::PluginManager::getObject<CodePaster::Service>()) {
// optional code pasting service
QAction *sendChunkToCodePasterAction = menu->addAction(tr("Send Chunk to CodePaster..."));
connect(sendChunkToCodePasterAction, &QAction::triggered, [this, fileIndex, chunkIndex]() {
connect(sendChunkToCodePasterAction, &QAction::triggered, this, [this, fileIndex, chunkIndex]() {
sendChunkToCodePaster(fileIndex, chunkIndex);
});
}
@@ -253,7 +253,7 @@ bool DiffEditorWidgetController::fileNamesAreDifferent(int fileIndex) const
void DiffEditorWidgetController::addApplyAction(QMenu *menu, int fileIndex, int chunkIndex)
{
QAction *applyAction = menu->addAction(tr("Apply Chunk..."));
connect(applyAction, &QAction::triggered, [this, fileIndex, chunkIndex]() {
connect(applyAction, &QAction::triggered, this, [this, fileIndex, chunkIndex]() {
patch(false, fileIndex, chunkIndex);
});
applyAction->setEnabled(chunkExists(fileIndex, chunkIndex) && fileNamesAreDifferent(fileIndex));
@@ -262,7 +262,7 @@ void DiffEditorWidgetController::addApplyAction(QMenu *menu, int fileIndex, int
void DiffEditorWidgetController::addRevertAction(QMenu *menu, int fileIndex, int chunkIndex)
{
QAction *revertAction = menu->addAction(tr("Revert Chunk..."));
connect(revertAction, &QAction::triggered, [this, fileIndex, chunkIndex]() {
connect(revertAction, &QAction::triggered, this, [this, fileIndex, chunkIndex]() {
patch(true, fileIndex, chunkIndex);
});
revertAction->setEnabled(chunkExists(fileIndex, chunkIndex));

View File

@@ -166,7 +166,7 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
settings.m_highlightBlocks = false;
SelectableTextEditorWidget::setDisplaySettings(settings);
connect(this, &TextEditorWidget::tooltipRequested, [this](const QPoint &point, int position) {
connect(this, &TextEditorWidget::tooltipRequested, this, [this](const QPoint &point, int position) {
const int block = document()->findBlock(position).blockNumber();
const auto it = m_fileInfo.constFind(block);
if (it != m_fileInfo.constEnd())
@@ -648,10 +648,10 @@ SideBySideDiffEditorWidget::SideBySideDiffEditorWidget(QWidget *parent)
};
setupHighlightController();
connect(m_leftEditor, &SideDiffEditorWidget::gotDisplaySettings, setupHighlightController);
connect(m_leftEditor, &SideDiffEditorWidget::gotDisplaySettings, this, setupHighlightController);
m_rightEditor->verticalScrollBar()->setFocusProxy(m_leftEditor);
connect(m_leftEditor, &SideDiffEditorWidget::gotFocus, [this]() {
connect(m_leftEditor, &SideDiffEditorWidget::gotFocus, this, [this]() {
if (m_rightEditor->verticalScrollBar()->focusProxy() == m_leftEditor)
return; // We already did it before.
@@ -672,7 +672,7 @@ SideBySideDiffEditorWidget::SideBySideDiffEditorWidget(QWidget *parent)
// too. We bring back the original policy to keep tab focus working.
m_leftEditor->setFocusPolicy(Qt::StrongFocus);
});
connect(m_rightEditor, &SideDiffEditorWidget::gotFocus, [this]() {
connect(m_rightEditor, &SideDiffEditorWidget::gotFocus, this, [this]() {
// Unhack #1.
m_rightEditor->verticalScrollBar()->setFocusProxy(nullptr);
// Unhack #2.

View File

@@ -304,7 +304,7 @@ void GitDiffEditorController::updateBranchList()
VcsCommand *command = GitPlugin::client()->vcsExec(
workingDirectory, {"branch", noColorOption, "-a", "--contains", revision}, nullptr,
false, 0, workingDirectory);
connect(command, &VcsCommand::stdOutText, [this](const QString &text) {
connect(command, &VcsCommand::stdOutText, this, [this](const QString &text) {
const QString remotePrefix = "remotes/";
const QString localPrefix = "<Local>";
const int prefixLength = remotePrefix.length();
@@ -830,12 +830,12 @@ void GitClient::chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex
menu->addSeparator();
QAction *stageChunkAction = menu->addAction(tr("Stage Chunk"));
connect(stageChunkAction, &QAction::triggered,
connect(stageChunkAction, &QAction::triggered, this,
[this, stageChunk, diffController, fileIndex, chunkIndex]() {
stageChunk(diffController, fileIndex, chunkIndex, false);
});
QAction *unstageChunkAction = menu->addAction(tr("Unstage Chunk"));
connect(unstageChunkAction, &QAction::triggered,
connect(unstageChunkAction, &QAction::triggered, this,
[this, stageChunk, diffController, fileIndex, chunkIndex]() {
stageChunk(diffController, fileIndex, chunkIndex, true);
});
@@ -1001,7 +1001,7 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
if (!argWidget) {
argWidget = new GitLogArgumentsWidget(settings(), editor->toolBar());
argWidget->setBaseArguments(args);
connect(argWidget, &VcsBaseEditorConfig::commandExecutionRequested,
connect(argWidget, &VcsBaseEditorConfig::commandExecutionRequested, this,
[=]() { this->log(workingDir, fileName, enableAnnotationContextMenu, args); });
editor->setEditorConfig(argWidget);
}
@@ -1087,7 +1087,7 @@ VcsBaseEditorWidget *GitClient::annotate(
if (!argWidget) {
argWidget = new GitBlameArgumentsWidget(settings(), editor->toolBar());
argWidget->setBaseArguments(extraOptions);
connect(argWidget, &VcsBaseEditorConfig::commandExecutionRequested,
connect(argWidget, &VcsBaseEditorConfig::commandExecutionRequested, this,
[=] {
const int line = VcsBaseEditor::lineNumberOfCurrentEditor();
annotate(workingDir, file, revision, line, extraOptions);