Qt Quick emulator layer crash - qt

I created an empty QT Quick Application and a ui.qml file in the project folder but I'm unable to open the ui file in design mode.
A dialog box describing error message says:
ine:1: Qt Quick emulator layer crash
Taking a look at line 1 of the code, i can't find any error
import QtQuick 2.12
import QtQuick.Controls 2.12
Item {
width: 400
height: 400
Page {
id: page
width: 200
height: 200
Button {
id: button
}
CheckBox {
id: checkBox
text: qsTr("Check Box")
}
Label {
id: label
text: qsTr("Label")
}
}
}
I tried changing the path for the QML EMULATOR but it didn't solve the issue.
path configurations
What can be the problem and how can it be fixed?

I ran into this error today. But I've successfully fixed it.
You need to do this:Tool->QT Quick->QT Quick Designer->QML Emulation Layer , "Use QML Emulation Layer that is built with selected QT"
No need to choose a path,
The solution was first in this thread.
Cannot Connect to QML Emluation Layer (QML Puppet)

Try changing Item to Rectangle. Not sure why but it works for me sometimes.

Related

Qt Creator autocomplete values for a global qml object in a file which is loaded by Stackloader?

So in QML, I can declare a stackview like this:
ApplicationWindow {
Item{
id: globalObject
specialProperty: "xyz"
}
StackView{
id: sv
}
}
Then I have a button which loads a "Page1.qml" file into the StackView. When the program runs, I can access the globalObject from code in Page1.qml but qtCreator's autocomplete is oblivious to this connection. It is not very quick to go back and forth between Page1.qml and main.qml to find the name of special property especially when there are many objects that have to be shared between multiple pages.
In general, what I want to know, is there a way to statically link a response to a dynamically loaded object or leave a hint for the IDE that the following objects in this file are available to this other file?

Using QML FileDialog leads to "Binding loop" in ToolBar

I have an issue that I can't solve by myself. I develop a UI using this third party library/framework - https://github.com/papyros/qml-material. It is with controls and layouts developed according to the Google Guidelines. The problem is that when I use FileDialog in the project, the page that it is defined in loads slowly and I get the following messages:
file:///C:/.../QtQuick/Controls/ToolBar.qml:146:9: QML QQuickItem*: Binding loop detected for property "layoutHeight"
file:///C:/.../QtQuick/Dialogs/DefaultFileDialog.qml:407:9: QML ToolBar: Binding loop detected for property "implicitHeight"
file:///C:/.../QtQuick/Dialogs/DefaultFileDialog.qml:407:9: QML ToolBar: Binding loop detected for property "implicitHeight"
It will be great if someone knows the answer.
The issue can be reproduced very easily with the Demo that is in the GitHub project of the library - https://github.com/papyros/qml-material/tree/develop/demo. Just add FileDialog somewhere there and see how the page will be loaded and what messages you will get.
Qt version used: 5.12.6
This is a somewhat known problem with FileDialogs when put in Loaders that are set to asynchronous loading. Here is a complete example demonstrating the problem:
import QtQuick.Window 2.12
import QtQuick.Dialogs 1.3
Window {
id: root
visible: true
width: 640
height: 480
Loader {
sourceComponent: FileDialog {}
asynchronous: true // change to false and ToolBar binding loop goes away
}
}
I noticed that the project you have referenced uses an asynchronous Loader in main.qml, so it appears that this is causing your issue. See line 243:
Loader {
id: example
anchors.fill: parent
asynchronous: true
I have found one bug report but it has been closed as unresolved. My understanding of this problem is that the error only affects the "backup" QFileDialog that only appears if an OS-specific one is not available. From the documentation:
The implementation of FileDialog will be a platform file dialog if possible. If that isn't possible, then it will try to instantiate a QFileDialog.
In my experience, on Windows and Mac, the binding loop error causes no problems and can be ignored because the OS file dialog always appears. I also don't think it is a correctable error outside of not using the asynchronous flag, as it is a Qt bug.

How can I call a function in ui.qml files in Qt Creator

I created a project in Qt Design Studio and then moved it to Qt Creator. I went through the conversion steps and now I only have .ui.qml files
Now I want call some functions in .ui.qml files. For example, I have a shape that I want to log a text by clicking on it. But qt creator alert me that I can not use functions or JavaScript blocks in Qt Quick UI forms.
errors in qt creator:
in Main.ui.qml :
import QtQuick 2.8
Item {
id: main
width: 1024
height: 768
Image {
id: someImage
MouseArea {
anchors.fill: parent
onClicked: {
// Here "JavaScript blocks are not supported in a Qt Quick UI
// form." error occurs
}
}
}
}

How does QML handle app quitting from menu bar on Mac?

I have an application which runs both on Windows and Mac.
The application is written in QML.
The most outer component in my QML code is an ApplicationWindow.
The ApplicationWindow component's API has a property called menuBar.
Here is a dummy example, which reproduces this with a MenuBar and a quitting Action:
ApplicationWindow {
id: _applicationWindow
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Component.onCompleted: {
console.info("ApplicationWindow completed.")
}
menuBar: MenuBar {
Menu {
title: "File"
MenuItem {
action: Action {
id: _myQuttingAction
text: "Quit MyApp"
shortcut: "Ctrl+Q"
onTriggered: {
// deinit...
console.info("I got called!")
Qt.quit()
}
}
}
}
}
}
When I run my application on Mac the following top menu bar titles appear:
Apple Icon menu | MyApp | File
If I drop down the "File" menu this is what I get:
As you can see the drop down is empty. Actually it isn't empty because it is pressable and if I press it, it does quit my application with all deinit calls in the action's onTriggered event.
If I drop down the "MyApp" menu, at the bottom I see "Quit MyApp" with the shortcut Cmd+Q. If I press this, this quits my application as well, but without calling my action's onTriggered event, thus my real application crashes on quit.
Unfortunately pressing Cmd+Q also calls the quit from the "MyApp" not my specified action.
On Windows I don't have this problem at all and the "Quit MyApp" appears under the "File" menu and does what I expect it to do.
I tried to google this problem and read the documentation without luck yet. Anybody know what is happening here?
It is not realistic to expect that Qt quitting will somehow magically use your particular menu action, which is completely optional and arbitrary.
It is possible that it is not your shortcut that's invoking the action, but something built in that is platform specific, like how Alt+F4 works on windoze for example.
Since you are using ApplicationWindow you can implement a custom exit handler, which will be used regardless how you quit the application:
onClosing: {
// do your stuff
close.accepted = true // exits, if set to false the quit request will be ignored
}
Update: Since you say the above code doesn't work as expected, the quitting must be happening at an even lower level that doesn't even notify qtquick, which could also explain the crashing. I don't currently have a macos machine to look into it, however there is decent chance you could get it to quit property by hooking a handler to the QCoreApplication::aboutToQuit() signal.

How to get the error message from a failed url load in a Qt WebView

say I have a basic QML file which listens for the onLoadFailed signal like this:
import QtQuick 1.1
import QtWebKit 1.0
WebView
{
onLoadFailed: {
}
url: "bogus_url"
}
In this example, I should get a 404 or a 500. What should I put in the onLoadFailed to output the error message that was returned?
I'm afraid you can't do it using a simple QML WebView.
You can use a [bad] trick described in this thread on the QT forum.
Otherwise you'll have to make your own QDeclarativeItem extending the WebView with all the infos you need.

Resources