我正在使用QtWebkit创建一个简单的浏览器,我设法添加了对Notification Web API it的支持,使用了QWebPage::setFeaturePermission
。
示例:
function notifyMe() {
if (Notification.permission === "granted") {
var notification = new Notification("Hi there!");
} else if (Notification.permission !== "denied") {
Notification.requestPermission(function(permission) {
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
}
<button onclick="notifyMe();">Notify me</button>
我的代码:
QObject::connect(page,
SIGNAL(featurePermissionRequested(QWebFrame*, QWebPage::Feature)), this,
SLOT(featurePermissionRequested(QWebFrame*,QWebPage::Feature))
);
...
void Form::featurePermissionRequested(QWebFrame* frame, QWebPage::Feature feature) {
switch (feature) {
case QWebPage::Notifications:
qDebug() << "Notification";
page->setFeaturePermission(frame, feature, QWebPage::PermissionGrantedByUser);
break;
case QWebPage::Geolocation:
qDebug() << "GEO";
break;
default:
qDebug() << "Unknown feature";
}
}
每次单击“通知我”按钮时,桌面上都会出现以下消息:
可以在QT中自定义通知吗?换句话说,与GoogleChrome或火狐相似,如下所示:
发布于 2015-03-11 15:26:49
新通知可以采用以下两个参数:
var notification = new Notification(title, options);
作为options对象的一部分,您可以传递要在通知中显示的'body‘和’图标‘。
https://stackoverflow.com/questions/28824296
复制相似问题