Reputation: 89
I'm trying to create own window class and use it in QML. In first steps I'm trying to subclass QQuickWindow in this way:
class TestWindow : public QQuickWindow {
Q_OBJECT
...
};
then in main.cpp file:
qmlRegisterType<TestWindow>("test.components", 1, 0, "TestWindow");
now in QML I can simply use it in such way:
import test.components 1.0
TestWindow {
//onClosing: console.log("closing")
//onVisibilityChanged: console.log(visibility)
}
The problem appears when I'll try to uncomment one of these lines. QML engine says that: ""TestWindow.onVisibilityChanged" is not available in test.components 1.0." Similar thing happens in case of "onClosing". I should be inherited from QWindow/QQuickWindow but I tried to create own anyway.
//connect(this, QQuickWindow::visibilityChanged, this, TestWindow::visibilityChanged);
and declare appropriate Q_PROPERTY with READ/WRITE and NOTIFY section defined as well. I replaced closing signal with "closingEvent" and did something like this:
//connect(this, SIGNAL(closing(QQuickCloseEvent*)), this, SIGNAL(closingEvent(QQuickCloseEvent*)));
which is also strange cuz when I try to use new signals/slots syntax, the compiler complains about incomplete QQuickCloseEvent which isn't described anywhere and seems to be something from Qt internals. So I had to stick with older code version.
After these treatments, The other "Window" (not TestWindow) from import QtQuick.Window 2.2 says that "x" and "y" properties are undefined. The more warnings/errors I'll try to fix, the more other things stops to work properly.
Has anyone had a similar problem?
edit: I find out that it has something to do with Q_REVISION macro used in case of some signals/slots/properties for both QWindow and QQuickWindow. I even tried to use these lines:
//qmlRegisterType<TestWindow>("test.components", 1, 0, "TestWindow");
//qmlRegisterType<TestWindow, 1>("test.components", 1, 0, "TestWindow");
qmlRegisterType<TestWindow, 2>("test.components", 1, 0, "TestWindow");
still without success.
Upvotes: 1
Views: 1033
Reputation: 89
I found a solution.
qmlRegisterType<TestWindow>("test.components", 1, 0, "TestWindow");
qmlRegisterRevision<QWindow, 1>("test.components", 1, 0);
qmlRegisterRevision<QQuickWindow, 1>("test.components", 1, 0);
I had to register revisions of base classes as well. The explanation described here: https://bugreports.qt.io/browse/QTBUG-22688 in comment.
Upvotes: 4