Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt5 How display a QML file
Forum Updated to NodeBB v4.3 + New Features

Qt5 How display a QML file

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 3 Posters 7.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chrisadams
    wrote on last edited by
    #2

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MIMIL38
      wrote on last edited by
      #3

      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&#40;"app.qml"&#41;);
      view.show();
      return app.exec();
      

      }@
      The content of app.qml is :

      import QtQuick 1.1
      import QtWebKit 3.0

      Rectangle {
      width: 360
      height: 360

      WebView {
              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.

      Sorry for my bad English, I'm French !
      Qt, it's cute !

      1 Reply Last reply
      0
      • shavS Offline
        shavS Offline
        shav
        wrote on last edited by
        #4

        Hi,

        Can you checking this example:
        @
        import QtQuick 2.0
        import QtWebKit 3.0

        Rectangle {
        width: 360
        height: 360

        TextInput {
            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!

        Mac OS and iOS Developer

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MIMIL38
          wrote on last edited by
          #5

          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...

          Sorry for my bad English, I'm French !
          Qt, it's cute !

          1 Reply Last reply
          0
          • shavS Offline
            shavS Offline
            shav
            wrote on last edited by
            #6

            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.

            Mac OS and iOS Developer

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MIMIL38
              wrote on last edited by
              #7

              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...

              Sorry for my bad English, I'm French !
              Qt, it's cute !

              1 Reply Last reply
              0
              • shavS Offline
                shavS Offline
                shav
                wrote on last edited by
                #8

                [quote author="MIMIL38" date="1357488386"]
                It would be nice if you have answers for the two others question[/quote]

                What question do you mean?

                Mac OS and iOS Developer

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MIMIL38
                  wrote on last edited by
                  #9

                  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 !

                  Sorry for my bad English, I'm French !
                  Qt, it's cute !

                  1 Reply Last reply
                  0
                  • shavS Offline
                    shavS Offline
                    shav
                    wrote on last edited by
                    #10

                    [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.

                    Mac OS and iOS Developer

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MIMIL38
                      wrote on last edited by
                      #11

                      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 !

                      Sorry for my bad English, I'm French !
                      Qt, it's cute !

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved