Skip to content

Instantly share code, notes, and snippets.

@torarnv
Created October 5, 2011 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torarnv/1264390 to your computer and use it in GitHub Desktop.
Save torarnv/1264390 to your computer and use it in GitHub Desktop.
#include <QApplication>
#include <QTimer>
#include <QtDeclarative>
#include <QDebug>
class WebView : public QDeclarativeItem
{
};
class WebViewExperimental : public QObject
{
Q_OBJECT
Q_PROPERTY(bool webGLEnabled READ webGLEnabled WRITE setWebGLEnabled)
public:
WebViewExperimental(QObject *parent = 0) : QObject(parent)
{
QTimer::singleShot(2000, this, SIGNAL(someRandomThingChanged()));
}
Q_INVOKABLE void yeah() { qDebug() << "Yeah"; }
bool webGLEnabled() const { return true; }
void setWebGLEnabled(bool enabled) {}
signals:
void someRandomThingChanged();
};
class WebViewExperimentalExtension : public QObject
{
Q_OBJECT
Q_PROPERTY(WebViewExperimental* experimental READ experimental)
public:
WebViewExperimentalExtension(QObject *extended = 0)
: QObject(extended)
, m_experimental(new WebViewExperimental(this))
{
}
WebViewExperimental *experimental() { return m_experimental; }
private:
WebViewExperimental *m_experimental;
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
qmlRegisterType<WebView>("QtWebKit", 3, 0, "WebView");
qmlRegisterExtendedType<WebView, WebViewExperimentalExtension>("QtWebKit.experimental", 3, 1, "WebView");
qmlRegisterUncreatableType<WebViewExperimental>("QtWebKit.experimental", 3, 1, "WebViewExperimental",
QString("Can't create instances of WebViewExperimental"));
QDeclarativeView view;
view.setSource(QUrl("qrc:/main.qml"));
view.show();
view.raise();
return app.exec();
}
#include "main.moc"
--- 8< ---
import QtQuick 1.1
import QtWebKit 3.0
import QtWebKit.experimental 3.1
Rectangle {
width: 800
height: 600
WebView {
anchors.fill: parent
experimental {
webGLEnabled: false
onSomeRandomThingChanged: experimental.yeah()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment