mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-19 20:32:15 +02:00
UI: Initialize YoutubeChatDock chat input members in constructor
Currently, the chat input elements (lineEdit, sendButton, and chatLayout) are initialized when the QCefWidget gets set. This is problematic behavior that only happened to work because we're a bit lucky: The chat is only enabled after a widget is set, and it's only set once. Without those conditions, the chat dock would crash when enabling the chat before a widget is set, and the elements would get recreated if the widget is set a second time, resulting in the original elements not getting freed and leaking. Moving the element creation to the constructor fixes both of these problems, as now they're created immediately and only once. Detected by PVS-Studio.
This commit is contained in:
parent
f462ffb224
commit
7cd5ede1e0
@ -350,7 +350,7 @@ std::shared_ptr<Auth> YoutubeAuth::Login(QWidget *owner,
|
||||
}
|
||||
|
||||
#ifdef BROWSER_AVAILABLE
|
||||
void YoutubeChatDock::SetWidget(QCefWidget *widget_)
|
||||
YoutubeChatDock::YoutubeChatDock(const QString &title) : BrowserDock(title)
|
||||
{
|
||||
lineEdit = new LineEditAutoResize();
|
||||
lineEdit->setVisible(false);
|
||||
@ -364,6 +364,14 @@ void YoutubeChatDock::SetWidget(QCefWidget *widget_)
|
||||
chatLayout->addWidget(lineEdit, 1);
|
||||
chatLayout->addWidget(sendButton);
|
||||
|
||||
QWidget::connect(lineEdit, &LineEditAutoResize::returnPressed, this,
|
||||
&YoutubeChatDock::SendChatMessage);
|
||||
QWidget::connect(sendButton, &QPushButton::pressed, this,
|
||||
&YoutubeChatDock::SendChatMessage);
|
||||
}
|
||||
|
||||
void YoutubeChatDock::SetWidget(QCefWidget *widget_)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout();
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(widget_, 1);
|
||||
@ -373,11 +381,6 @@ void YoutubeChatDock::SetWidget(QCefWidget *widget_)
|
||||
widget->setLayout(layout);
|
||||
setWidget(widget);
|
||||
|
||||
QWidget::connect(lineEdit, &LineEditAutoResize::returnPressed, this,
|
||||
&YoutubeChatDock::SendChatMessage);
|
||||
QWidget::connect(sendButton, &QPushButton::pressed, this,
|
||||
&YoutubeChatDock::SendChatMessage);
|
||||
|
||||
cefWidget.reset(widget_);
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ private:
|
||||
QHBoxLayout *chatLayout;
|
||||
|
||||
public:
|
||||
inline YoutubeChatDock(const QString &title) : BrowserDock(title) {}
|
||||
YoutubeChatDock(const QString &title);
|
||||
void SetWidget(QCefWidget *widget_);
|
||||
void SetApiChatId(const std::string &id);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user