[PyQt] Problem with QQmlApplicationEngine

Selim Tuvi selim.tuvi at dreamworks.com
Thu Dec 5 17:10:23 GMT 2013


engine.rootObjects() already returns a list of QQuickWindow instances. Just
change your code as follows:

win = engine.rootObjects()[0]
win.show()

sys.exit(app.exec_())

-Selim


On Tue, Nov 26, 2013 at 11:07 PM, Charlie Gentil <
ceg at redaction-developpez.com> wrote:

>  Hello,
>
>
>
> I write a program PyQt5.1 and Qt Quick. I wish I could use MenuBar and I
> try to use QQmlApplicationEngine.
>
>
>
> When I run my Python script a white window appears without the MenuBar,
> but I have no default.
>
>
>
> Here are my codes:
>
>
>
> test.py
>
> #!/usr/bin/env python
>
> # -*- coding: utf-8 -*-
>
>
>
> import sys
>
> from PyQt5.QtCore import QObject, QUrl, QSize
>
> from PyQt5.QtWidgets import QApplication
>
> from PyQt5.QtQuick import QQuickView, QQuickWindow
>
> from PyQt5.QtQml import qmlRegisterType, QQmlApplicationEngine
>
>
>
>
>
>
>
> class MainClass(QObject):
>
> def __init__(self, parent=None):
>
> super(MainClass, self).__init__(parent)
>
>
>
> qmlRegisterType(MainClass, "Charts", 1, 0, "MainClass")
>
>
>
> app = QApplication(sys.argv)
>
> engine = QQmlApplicationEngine('test.qml')
>
> topLevel= engine.rootObjects()[0]
>
> win = QQuickWindow(topLevel)
>
> win.show()
>
> sys.exit(app.exec_())
>
>
>
>
>
>
>
> test.qml
>
> import QtQuick 2.1
>
> import QtQuick.Controls 1.0
>
>
>
> ApplicationWindow {
>
> id: application
>
>
>
> menuBar : MenuBar {
>
> Menu {
>
> title: "File"
>
> MenuItem { text: "Open..." }
>
> MenuItem { text: "Close" }
>
> }
>
>
>
> Menu {
>
> title: "Edit"
>
> MenuItem { text: "Cut" }
>
> MenuItem { text: "Copy" }
>
> MenuItem { text: "Paste" }
>
> }
>
> }
>
>
>
>
>
> }
>
>
>
>
>
> Can you help me.
>
>
>
> In advance thank you
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20131205/6cfeef8a/attachment-0001.html>


More information about the PyQt mailing list