這是去年的一個項目,雖然研究出來了,解了一時之需,但隨後束之高閣。當時Qt的版本是4.8。如今整理以下:ui
把QT HTML5 APP改形成 QML App 方案spa
新建一個QML自定義控件,該控件包含QT Webview, 而後由QT WebWiew 的負責Javasript和C++的交互。blog
新建一個QML自定義控件ip
import QtQuick 1.0 ci import MyWebView 1.0 get
Rectangle { it width: 800 io height: 480 event
MyWebView{ table
} } |
MyWebView.h
#ifndef MYWEBVIEW_H #define MYWEBVIEW_H
#include <QtDeclarative/QDeclarativeExtensionPlugin> #include <QtDeclarative/qdeclarative.h> #include <QtGui/QGraphicsProxyWidget> #include <QtGui/QPushButton> #include <QDebug> #include <QtWebKit/QWebView> #include <QtWebKit/QWebFrame>
class MyWebView : public QGraphicsProxyWidget { Q_OBJECT public: explicit MyWebView(QGraphicsProxyWidget *parent = 0); ~MyWebView();
signals:
public slots:
private slots: void addToJavaScript();
private: QWebView* m_pWebView;
Adapter* m_pAdapter;
bool event(QEvent*);
}; #endif // MYWEBVIEW_H |
註冊用戶控件
#ifndef VIEW_H #define VIEW_H
#include <QtCore/qglobal.h>
#if defined(VIEW_LIBRARY) # define VIEWSHARED_EXPORT Q_DECL_EXPORT #else # define VIEWSHARED_EXPORT Q_DECL_IMPORT #endif
int VIEWSHARED_EXPORT RegisterView();
#endif // VIEW_H
int RegisterView() { int iType = qmlRegisterType<MyWebView>("MyWebView", 1, 0, "MyWebView"); qDebug ("qmlRegisterType = %d",iType); return iType; } |