GithubHelp home page GithubHelp logo

Comments (2)

labsin avatar labsin commented on August 24, 2024

It's because ApplicationWindow is a QWindow and not a QQuickItem
QWindow has a method setParent(QWindow) but the ApplicationWindow has no property and this has a whole other meaning than that of QQuickItem's parent and also of QObject.
Some info:
http://qt-project.org/doc/qt-5.0/qtquick/qtquick-visualcanvas-visualparent.html
http://qt-project.org/doc/qt-5.1/qtquick/qquickwindow.html

Chances are high you don't want this.

from qml.

niemeyer avatar niemeyer commented on August 24, 2024

@labsin is right: when you use a Window or ApplicationWindow as the root of your QML tree, what you get out of window.Root() is not a QQuickItem_, so you cannot set the "parent" property of another QQuickItem_ to it. That's the reason why it crashes. You can fix your code, as described at the bottom, but there's still a bug here: crashing in such a cryptic way is terrible for such a trivial operation.

This was just fixed on commit 7c2a7c6. Now that erroneous logic will crash the application with the following message:

panic: cannot set property "parent" with type QQuickItem* to value of QQuickWindow*

This should hopefully make the problem more obvious.

So, knowing what's wrong, you can fix your code and keep the Window as the root of the QML code. For example, you can declare the QML code along the lines of:

Window {
    Rectangle {
        objectName: "rect"
    }
}

Then, inside your Go code change the parent with:

obj.Set("parent", win.Root().ObjectByName("rect"))

This should achieve the same result of the original example.

from qml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.