#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QtWebEngine/qtwebengineglobal.h>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtWebEngine::initialize();
QQmlApplicationEngine engine;
engine.load(QUrl("main.qml"));
return app.exec();
}
import QtQuick 2.0
import QtWebEngine 1.0
import QtQuick.Controls 1.3
import QtQuick.Window 2.0
ApplicationWindow {
title: qsTr("Test")
width: 1200
height: 800
visible: true
WebEngineView {
width: Screen.width
height: Screen.height
anchors.fill: parent
url: 'http://duckduckgo.com'
}
}
TARGET = browser
TEMPLATE = app
SOURCES = main.cpp
QT += qml quick webengine
PASS
/usr/local/Cellar/qt5/5.4.0/bin/qmlscene main.qml
FAIL
qmake
make
then I clicked on browser.app
, the application starts but no window opened.
Any hint about what I am doing wrong?
I guess the file main.qml is not found. You should get an error message "... File not found" in the console.
To solve this problem either supply a valid path on your drive or use Qt's resource management. This is documented here , I'll outline the steps:
1) Create file test.qrc with the following contents:
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>
2) Add test.qrc to webengine.pro
RESOURCES += test.qrc
3) Modify main.cpp to load the qml file from the resources:
engine.load(QUrl("qrc:/main.qml"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.