Qt WebView改形成 QML App

这是去年的一个项目,虽然研究出来了,解了一时之需,但随后束之高阁。当时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;

}

相关文章
相关标签/搜索