//实例化搜索对象并关联信号槽
OnvifSearch *search = new OnvifSearch(this);
connect(search, SIGNAL(receiveDevice(OnvifDeviceInfo)), this, SLOT(receiveDevice(OnvifDeviceInfo)));
//参数1是网卡地址/参数2指定地址则表示单播
search->search("192.168.0.110", "");
void frmSimple::receiveDevice(const OnvifDeviceInfo &deviceInfo)
{
QString msg = QString("收到设备: %1").arg(deviceInfo.onvifAddr);
ui->textEdit->append(msg);
QListWidgetItem *item = new QListWidgetItem;
item->setText(deviceInfo.deviceIp);
item->setData(Qt::UserRole, deviceInfo.onvifAddr);
ui->listWidget->addItem(item);
}
//实例化onvif对象实例
OnvifDevice *device = new OnvifDevice(this);
//设置用户信息用于请求的时候认证用
device->setUserInfo("admin", "123456");
//设置请求地址
device->setOnvifAddr("http://192.168.0.64/onvif/device_service");
//先获取服务文件
device->getServices();
//可能为空需要按照另一种方式获取
if (device->getMediaUrl().isEmpty()) {
device->getCapabilities();
}
//获取配置文件
QList<OnvifProfileInfo> profiles = device->getProfiles();
foreach (OnvifProfileInfo profile, profiles) {
ui->cboxProfiles->addItem(profile.token);
}
//对指定的配置文件获取视频地址
QString token = ui->cboxProfiles->currentText();
QString url = device->getStreamUri(token);
ui->txtStreamUri->setText(url);