Qt5 How display a QML file
-
I've started a QML project, but I don't know how to display it into a window.
I know, I can use qmlview.exe, but I think there is another way to do it with Qt Creator, is'nt it ?
Please assist me ! In the meantime, I continue my search !MIMIL38
-
You can either use qmlscene as described "here":http://doc-snapshot.qt-project.org/5.0/qtquick/qtquick-quickstart-basics.html#loading-and-displaying-the-qml-document or you can define your own C++ entrypoint with a QQuickView as described "here":http://doc-snapshot.qt-project.org/5.0/qtquick/qquickview.html
Cheers,
Chris. -
Thank you very much for the links,
But I've a problem : This code displays a little and empty window.
@
#include <QtQuick/QtQuick>
#include <QGuiApplication>int main (int argc, char *argv[])
{
QGuiApplication app(argc, argv);QQuickView view(QUrl::fromLocalFile("app.qml")); view.show(); return app.exec();
}@
The content of app.qml is :import QtQuick 1.1
import QtWebKit 3.0Rectangle {
width: 360
height: 360WebView { id: webview x: 0 y: 0 url: "http://qt-project.org" width: parent.width height: parent.height } TextInput { id: text_input1 x: 32 y: 29 width: 278 height: 20 color: red text: qsTr("url") font.pixelSize: 12 onTextChanged: { webview.url = text; } }
}
I think there is a problem. But I don't know where it is. (Maybe it's between the keyboard and the chair)I've an other problem : what is the include's path for QWebView (in C++) because I've download Qt 5.0.0 yesterday and I'd like to use a project created with Qt 4.7 with Qt 5.0.0.
In the documentation, it was written this :
#include <QWebView>
(Like in Qt 4.7)
But it's not working with me. -
Hi,
Can you checking this example:
@
import QtQuick 2.0
import QtWebKit 3.0Rectangle {
width: 360
height: 360TextInput { id: address anchors.top: parent.top width: parent.width height: 20 selectByMouse: true text:"http://google.com" onAccepted: { console.log(address.text); container.url = address.text; } } WebView { id: container anchors.bottom: parent.bottom width: parent.width height: parent.height - address.height }
}
@It's works for Qt 5.0 and QML 2.0. For apply the new url you must pressed Enter key.
I hope this help you!
-
Thank you very much !
Now I know what was the problem : I used QtQuick 1.1. When I use QtQuick 2.0, it's working. But when I try to see app.qml into Qt Designer, there is a error : unsupported QtQuick version. That's why I used QtQuick 1.1...
And does anyone know what is the include's path of QWebView in Qt 5.0 ?
I have another question : is it true that the QtWebKit2 is just available with the QML ? It seems to me that this is what I read in the documentation... -
I don’t use Designer in my projects. But I checked it and get this issue. Also I found this "link":http://www.qtcentre.org/threads/52503-Qt-Creator-2-6-1-on-OSX-10-8-2-and-QML.
But I do not known How to fix it :-(.
Maybe this is "answer":http://www.qtcentre.org/threads/52569-QtQuick-2-0-doesn-t-work-on-OSX-Mountain-Lion-10-8-2?p=235388#post235388.
-
Thank you !
I think Qt Designer is not ready to display QML files (maybe in a future release...).
It would be nice if you have answers for the two others question ! I continue my search, but I don't find anything... -
[quote author="MIMIL38" date="1357488386"]
It would be nice if you have answers for the two others question[/quote]What question do you mean?
-
bq. And does anyone know what is the include’s path of QWebView in Qt 5.0 ?
I have another question : is it true that the QtWebKit2 is just available with the QML ? It seems to me that this is what I read in the documentation…
Thank very much for all your replies ! -
[quote author="MIMIL38" date="1357465297"]
And does anyone know what is the include's path of QWebView in Qt 5.0 ?[/quote]If you need use WebKit in C++ code you may use this:
@
#include <QtWebKit/QtWebKit> //For WebKit
#include <QtWebkitWidgets/QtWebKitWidgets> //For QWebView and others widgets for showing HTML
@Also you must enabled two modules in your .pro file.
@
QT += webkit webkitwidgents
@[quote author="MIMIL38" date="1357465297"]I have another question : is it true that the QtWebKit2 is just available with the QML ?[/quote]
No, you may use QtWebKit in Widget-based applications. See my first answer. -
Now, whan I cmpile the modified code, I have 624 errors like that : main.obj:-1: erreur : LNK2019: symbole externe non résolu "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (_imp??1QApplication@@UAE@XZ) référencé dans la fonction _main in english, I would give it : main.obj:-1: error : LNK2019: unresolved extern symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (_imp??1QApplication@@UAE@XZ) referencedin the function _main
If you know what it is, please tell me the solution !