该函数会根据是新建还是添加现在执行不同的流程:
void OBSBasicSourceSelect::on_buttonBox_accepted()
bool useExisting = ui->selectExisting->isChecked();//新建按钮是否选中
bool visible = ui->sourceVisible->isChecked();//便源可见选项
if (useExisting){
else //添加新源
//名称是否为空,默认名为媒体源
if (ui->sourceName->text().isEmpty()) {
OBSMessageBox::warning(this,
QTStr("NoNameEntered.Title"),//请输入一个有效的名称
QTStr("NoNameEntered.Text"));//您不能使用空白名称。
return;
//添加新源
if (!AddNew(this, id, QT_TO_UTF8(ui->sourceName->text()), visible, newSource))
return;
done(DialogCode::Accepted);
AddNew函数的原理校验用户输入的名称重复性,如果不重复,就创建源实例,创建后的新源实例加入场景中。
bool AddNew(QWidget *parent, const char *id, const char *name,
const bool visible, OBSSource &newSource)
//获取主窗口
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
//获取主窗口当前的场景
OBSScene scene = main->GetCurrentScene();
bool success = false;
if (!scene)
return false;
//是否名字已经存在
OBSSourceAutoRelease source = obs_get_source_by_name(name);
if (source && parent) {
OBSMessageBox::information(parent, QTStr("NameExists.Title"),
QTStr("NameExists.Text"));
const char *v_id = obs_get_latest_input_type_id(id);
source = obs_source_create(v_id, name, NULL, nullptr);
if (source)
AddSourceData data;
data.source = source;
data.visible = visible;
//添加到当彰场景中
obs_enter_graphics();
obs_scene_atomic_update(scene, AddSource, &data);
obs_leave_graphics();
return success;
if (should_show_properties(sourceSelect.newSource, id)) {
CreatePropertiesWindow(sourceSelect.newSource);
新创建的源是struct obs_source_t类型,新创建的源需要进行配置。所以这里会通过CreatePropertiesWindow函数创建并显示属性对话框。
void OBSBasic::CreatePropertiesWindow(obs_source_t *source)
bool closed = true;
if (properties)
closed = properties->close();
if (!closed)
return;
properties = new OBSBasicProperties(this, source);
properties->Init();
properties->setAttribute(Qt::WA_DeleteOnClose, true);
如对于视频媒体源加的属性对话框: