Qt 5.9.5 webengine 開發
阿新 • • 發佈:2019-02-18
QtWebkits在Qt5.6以上版本被淘汰了,目前而言,QWebEngine有以下缺點:MinGW版本的Qt不支援,即便是Qt5.9.5版本以上也是不支援的。僅僅支援MSVC版本,介面暫時不豐富,無法和QWebFrame進行互動(使用了新的QWebChannel和QWebEnginePage組合進行互動)
在使用的時間安裝新版本的Qt要安裝Qt MSVC版本的,記得選擇webengine元件
在example裡面有很多例子,說不上有多友好,但也不錯。
在webview,webengine,webenginewidgets三個目錄下面都有,minimal是屬於小巧的那種,程式碼很少,很容易讀。
minimal.pro
TEMPLATE=app
QT+=webenginewidgets
SOURCES+=main.cpp
target.path=$$[QT_INSTALL_EXAMPLES]/webenginewidgets/minimal
INSTALLS+=target
main.cpp
/****************************************************************************
**
**Copyright(C)2016TheQtCompanyLtd.
**Contact:https://www.qt.io/licensing/
**
**ThisfileispartoftheexamplesoftheQtToolkit.
**
**$QT_BEGIN_LICENSE:BSD$
**CommercialLicenseUsage
**LicenseesholdingvalidcommercialQtlicensesmayusethisfilein
**accordancewiththecommerciallicenseagreementprovidedwiththe
**Softwareor,alternatively,inaccordancewiththetermscontainedin
**awrittenagreementbetweenyouandTheQtCompany.Forlicensingterms
**andconditionsseehttps://www.qt.io/terms-conditions.Forfurther
**informationusethecontactformathttps://www.qt.io/contact-us.
**
**BSDLicenseUsage
**Alternatively,youmayusethisfileunderthetermsoftheBSDlicense
**asfollows:
**
**"Redistributionanduseinsourceandbinaryforms,withorwithout
**modification,arepermittedprovidedthatthefollowingconditionsare
**met:
***Redistributionsofsourcecodemustretaintheabovecopyright
**notice,thislistofconditionsandthefollowingdisclaimer.
***Redistributionsinbinaryformmustreproducetheabovecopyright
**notice,thislistofconditionsandthefollowingdisclaimerin
**thedocumentationand/orothermaterialsprovidedwiththe
**distribution.
***NeitherthenameofTheQtCompanyLtdnorthenamesofits
**contributorsmaybeusedtoendorseorpromoteproductsderived
**fromthissoftwarewithoutspecificpriorwrittenpermission.
**
**
**THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS
**"ASIS"ANDANYEXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOT
**LIMITEDTO,THEIMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFOR
**APARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALLTHECOPYRIGHT
**OWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
**SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOT
**LIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,
**DATA,ORPROFITS;ORBUSINESSINTERRUPTION)HOWEVERCAUSEDANDONANY
**THEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,ORTORT
**(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSE
**OFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE."
**
**$QT_END_LICENSE$
**
****************************************************************************/
#include<QApplication>
#include<QWebEngineView>
intmain(intargc,char*argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplicationapp(argc,argv);
QWebEngineViewview;
view.setUrl(QUrl(QStringLiteral("http://www.qt.io")));
view.resize(1024,750);
view.show();
returnapp.exec();
}