Open quantonganh opened 5 years ago
I found the reason:
ApplicationWindow
type must be used instead of Window
: http://doc.qt.io/qt-5/qml-qtquick-controls-applicationwindow.htmlApplicationWindow is a Window that adds convenience for positioning items, such as MenuBar, ToolBar, and StatusBar in a platform independent manner.
import QtQuick.Controls 1.4
to make menu bar works.@quantonganh it shouldn't crashed though, usually just a javascript error. @therecipe probably there's a bug in the binding ?
@quantonganh
You can probably also use QtQuick.Controls 2.4
This patch should make the menuBar work for https://github.com/therecipe/examples/tree/master/basic/qml as well
diff --git a/basic/qml/qml/main.qml b/basic/qml/qml/main.qml
index b7d4682..5aff65b 100644
--- a/basic/qml/qml/main.qml
+++ b/basic/qml/qml/main.qml
@@ -1,5 +1,5 @@
import QtQuick 2.7 //ApplicationWindow
-import QtQuick.Controls 2.1 //Dialog
+import QtQuick.Controls 2.4 //Dialog
ApplicationWindow {
id: window
@@ -9,6 +9,18 @@ ApplicationWindow {
minimumWidth: 250
minimumHeight: 200
+ menuBar: MenuBar {
+ Menu {
+ id: helpMenu
+ title: "Help"
+
+ MenuItem {
+ text: "Check for Updates..."
+ onTriggered: console.log("test")
+ }
+ }
+ }
+
Column {
anchors.centerIn: parent
rebuild and my app crashed without any logs even enabled: QT_DEBUG QT_DEBUG_CONSOLE QT_DEBUG_PLUGINS Why? How can I debug this?
Usually the need to explicitly export QT_DEBUG_CONSOLE=true
on windows should be gone now for qtdeploy -fast
or plain go run/build
builds.
It is only necessary now, if you want to have the debug console for "full" deployment builds like this qtdeploy build && .\deploy\windows\${APPNAME}.exe
Can you get "println" to print something to the console before it crashes?
@arknable
I'm not sure, but as you said this usually should just result in an js error.
For example if I run the code from above with import QtQuick.Controls 2.1
instead of import QtQuick.Controls 2.4
I simply get
QQmlApplicationEngine failed to load component
qrc:/qml/main.qml:12 MenuBar is not a type
as expected.
My application is working fine. Then I tried to add a menu bar like this:
rebuild and my app crashed without any logs even enabled:
Why? How can I debug this?