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. How to create a Window using QML ?
Forum Update on Monday, May 27th 2025

How to create a Window using QML ?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 6.8k Views
  • 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.
  • W Offline
    W Offline
    weiyuemin
    wrote on 11 Jan 2013, 02:53 last edited by
    #1

    I know now to create a QML window in C++, but my qml code will frequently operate the window, so I want to create the window using QML.
    I wan't to write code like this:

    @
    Window {
    id: test_win
    source: "Component/xxx.qml"
    }
    @

    I wrote a class MyWindow derived from QDeclarativeView, and called qmlRegisterType.
    the MyWindow always use a global QDeclarativeView as father.

    but when I setSource to the global QDeclarativeView, error occurs:

    ASSERT: "!d->isWidget" in file kernel\qobject.cpp, line 1894

    Can anyone help?

    Thank you!

    I notice http://qt-project.org/doc/qt-5.0/qtquick/qmlmodule-qtquick-window2-qtquick-window-2.html in Qt5's document, but I'm currently still using Qt4, and I didn't found a QtQuick.Window 1.0 in Qt4..

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 11 Jan 2013, 07:59 last edited by
      #2

      QtQuick.Window is part of QtQuick2 and is not available in Qt4 (and is not going to be - Qt4 is considered feature complete, it will only receive bug fixes in the future).

      Interesting approach on your side, I don't see why it is not working. Maybe other declarative children interfere (a Window inside would be parented to it's QML parent, but you force it to reparent to global QDeclarativeView).

      Have you looked up the failing ASSERT code in QObject? I had some situations where a simple commenting out of an assert solved problems (that was back when Qt5 was rough, long before the alpha). If you do that, though, remember about GPL/ LGPL requirements.

      (Z(:^

      1 Reply Last reply
      0
      • W Offline
        W Offline
        weiyuemin
        wrote on 11 Jan 2013, 09:37 last edited by
        #3

        Well, according to the ASSERT, I know that a QWidget cannot be directly put into QML code, but QDeclarativeView is inherited from QWidget, and MyWindow is inherited from QDeclarativeView, so the ASSERT failed.

        Another way is make MyWindow inherited from QObject and make a QDeclarativeView as a member of MyWindow, but this also lead to many code(rewritten of many properties, such as size, pos)

        So I finally give up this try. Thank you:)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jens
          wrote on 12 Jan 2013, 07:43 last edited by
          #4

          In desktop components we also expose a Window just like this. (which is no longer needed in Qt 5) But you can see if it works better for you.

          https://qt.gitorious.org/qtplayground/qtdesktopcomponents (qt4 branch)

          1 Reply Last reply
          0

          1/4

          11 Jan 2013, 02:53

          • Login

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