Skip to content

Commit

Permalink
fix memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nschimme committed Sep 29, 2023
1 parent 20f31c3 commit 49dc320
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/adventure/adventurewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AdventureWidget::AdventureWidget(AdventureTracker &at, QWidget *const parent)
, m_adventureTracker{at}
{
m_textEdit = new QTextEdit(this);
m_textCursor = new QTextCursor(m_textEdit->document());
m_textCursor = std::make_unique<QTextCursor>(m_textEdit->document());

m_textEdit->setReadOnly(true);
m_textEdit->setOverwriteMode(true);
Expand All @@ -32,9 +32,11 @@ AdventureWidget::AdventureWidget(AdventureTracker &at, QWidget *const parent)

QTextCharFormat blockCharFormat = m_textCursor->blockCharFormat();
blockCharFormat.setForeground(settings.foregroundColor);
auto font = new QFont();
font->fromString(settings.font); // need fromString() to extract PointSize
blockCharFormat.setFont(*font);
{
QFont font;
font.fromString(settings.font); // need fromString() to extract PointSize
blockCharFormat.setFont(font);
}
m_textCursor->setBlockCharFormat(blockCharFormat);

auto layout = new QVBoxLayout(this);
Expand All @@ -45,7 +47,7 @@ AdventureWidget::AdventureWidget(AdventureTracker &at, QWidget *const parent)

addDefaultContent();

m_clearContentAction = new QAction("Clear Content");
m_clearContentAction = new QAction("Clear Content", this);
connect(m_clearContentAction,
&QAction::triggered,
this,
Expand Down
2 changes: 1 addition & 1 deletion src/adventure/adventurewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ private slots:
AdventureTracker &m_adventureTracker;

QTextEdit *m_textEdit = nullptr;
QTextCursor *m_textCursor = nullptr;
std::unique_ptr<QTextCursor> m_textCursor;
QAction *m_clearContentAction = nullptr;
};
4 changes: 2 additions & 2 deletions src/display/prespammedpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ static constexpr const bool USE_TEST = true;
static constexpr const bool USE_TEST = false;
#endif

PrespammedPath::PrespammedPath(QObject * /*unused*/)
// REVISIT: why isn't the parent passed to the base class?
PrespammedPath::PrespammedPath(QObject *parent)
: QObject(parent)
{
if (USE_TEST) {
m_queue.append(CommandEnum::DOWN);
Expand Down

0 comments on commit 49dc320

Please sign in to comment.