FileDialog in Qml not working in Release - c++

I am working on project with Qt Quick Control 2.
When I try to run my software in debug mode FileDialog.qml opens perfectly but when I deploy it as release mode it doesn't work.
Here is my code:
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
import QtQuick.Dialogs 1.0
// File Dialog to browse
FileDialog {
id: openDialog
title: "Please Select An Image"
folder: shortcuts.pictures
nameFilters: ["Image files (*.BMP)"]
modality: Qt.NonModal
selectExisting: true
/*
* do my stuff
*/
}

Here it is my Js function that calls FileBrowse.qml (file in parameters).
I call this function in other view like this :
JsCommonCall.openFileDialog("frameFileBrowse.qml",2)
function openFileDialog(file,
parentCalled) {
_component = Qt.createComponent(file);
_popUp = _component.createObject(windowsMain, {"x": offsetPopUpCreate,
"y": offsetPopUpCreate,
"parentCall":parentCalled});
if(_popUp !== null)
_popUp.open()
}
here it is my FileBrowse
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Dialogs 1.0
// File Dialog to browse
FileDialog {
id: openDialog
title: "Please Select An Image"
folder: shortcuts.home
nameFilters: ["Image files (*.BMP)"]
selectFolder: true
// variables
property int parentCall;
onAccepted: {
imgCurrentCam1.source = openDialog.fileUrl;
openDialog.close()
}
onRejected: {
openDialog.close()
}
}

This is working for me
FileDialog {
id: fdExport
title: qsTr("File name")
folder: shortcuts.home
selectFolder: true
onAccepted: {
}
}
and to run
fdExport.open()
Please try to leave
modality: Qt.NonModal
from your code.

I don't know which is the problem but the code below is perfectly portable on Windows machines. Tested in Linux too.
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
FileDialog {
id: fdImport
title: qsTr("File name")
folder: shortcuts.home
onAccepted: {
textEdit.text= fdImport.fileUrls[0]
}
}
Rectangle {
id: rectangle
color: "#ffffff"
anchors.fill: parent
Rectangle {
id: rectangle1
color: "#ffffff"
anchors.right: parent.right
anchors.rightMargin: 8
anchors.left: parent.left
anchors.leftMargin: 8
anchors.bottom: rectangle2.top
anchors.bottomMargin: 6
anchors.top: parent.top
anchors.topMargin: 8
TextEdit {
id: textEdit
text: qsTr("Text Edit")
anchors.fill: parent
font.pixelSize: 12
}
}
Rectangle {
id: rectangle2
y: 441
width: 128
height: 32
color: "#ffffff"
anchors.left: parent.left
anchors.leftMargin: 8
anchors.bottom: parent.bottom
anchors.bottomMargin: 7
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
fdImport.open()
}
Text {
id: text1
text: qsTr("Click me!")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
font.pixelSize: 12
}
}
}
}
}
The qt.conf file
[Paths]
Plugins=plugins
Libraries=libs
Please remember to copy all the dll (release) in the executable folder, with the qml and plugins folders.

One strange but possible reason for it is anti-virus: my FileDialog isn't opening either, and the entire QML application is hanging, while the AV is active.

Related

C++ [QT 5.15.2] : virtual keyboard shift button is disabled until I click on my textField

I'm developping an app using QT 5.15 LTS (5.15.2). I have the following QML item that I use to handle virtual keyboard interactions :
//InputScreen.qml
import QtQuick 2.3
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import QtQuick.VirtualKeyboard 2.3
Rectangle
{
id: inputScreen
property var target: undefined
width: app.width
height: app.height
color: "#44000000"
z: 200
onVisibleChanged:
{
if (inputScreen.visible == true)
{
fld.text = target.text;
inputPanel.forceActiveFocus();
fld.forceActiveFocus();
fld.clicked(); //Tried to force a click here. Explanation below
}
}
Rectangle
{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
height: 40
width: 600
z: 201
TextField
{
id: fld
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
width: 400
height: 40
font.pixelSize: 24
focus: true
}
Button
{
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
width: 200
height: 40
font.pixelSize: 24
text: "Valider"
onClicked:
{
if (target != undefined)
{
target.text = fld.text;
inputScreen.visible = false;
}
}
}
}
InputPanel
{
id: inputPanel
height: 400
width: app.width - 40
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
focus: true
z: 201
}
MouseArea
{
anchors.fill: parent
onClicked:
{
target.text = fld.text;
inputScreen.visible = false;
}
}
}
When my item becomes visible, the textField gets the focus correctly and I can start typing through the InputPanel virtual keyboard. There's however one single problem : the shift key does not work !
In order to make that shift key enable itself, I need to click on the TextField, which beats the purpose of forcing the active focus on it to begin with.
Is there any way to fix that problem ? Or at the very least, is there any kind of workaround I can use to enable that shift key ?
I have already tried to force a click inside my TextField (as seen in the code above), but it didn't work.
For context : here's the content of main.qml as well, in order to give out a working example :
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls 1.4
import QtQuick.VirtualKeyboard 2.3
Window
{
id: app
visible: true
width: 640
height: 480
title: qsTr("Example")
InputScreen
{
id: inputScreen
visible: false
}
Rectangle
{
id: rect
height: parent.height * 0.8
width: parent.width * 0.8
anchors.centerIn: parent
border.color: "#FF0000"
z: 1
TextField
{
id: myField
anchors.centerIn: parent
width: 200
height: 24
MouseArea
{
anchors.fill: parent
onClicked:
{
inputScreen.target = myField;
inputScreen.visible = true;
}
}
}
}
}
I finally managed to find a trick that enabled that shift key without requiring to click on my already focused TextField, and it's actually very simple.
I simply added the following line in the onClicked event of the MouseArea inside the "myField" TextField :
MouseArea
{
anchors.fill: parent
onClicked:
{
parent.focus = true; //This line solved the issue !
//...
}
}
I have no idea why, but somehow this was enough to actually unlock the shift key from my InputPanel virtual keyboard without requiring me to click a second time on the TextField from my InputScreen item. I suppose it has probably something to do with the fact that my MouseArea is hijacking the focus of the "myField" TextField, which triggers some sort of odd behaviour on the InputPanel item despite having another TextField item focused.
In any case, I hope this will help someone.

QT Text.WordWrap not working inside ColumnLayout

I am developing application using QT QML. I am facing one strange issue with QML. I want to divide and display long text using QML. I am using QT Text element to perform this task. I want to place this Text inside QT Columnlayout with other UI elements. I am not able to display long text as Multi line text. Please help me to solve this problem. Here is my QML code.
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
color: "#18d28a"
ColumnLayout{
id: base_coloumn_layout
width: parent.width
Layout.margins: 10
Text {
id: application_instruction
width: 640
text: qsTr("xyxvx dgdgdh dhdgdd dhdgdhhgd dhhhdgd dhdgdg dhdgdh djhddh djddgdhgdh dhdgdhgdgh dhgdgdhj dhdgdghdg dhjdgdgd.")
color: "#000000"
font.pointSize: 12
wrapMode: Text.WordWrap
}
}
}
Same element is working properly when placed outside ColoumnLayout. I am able to display Text as multi line with code bellow. I want same code should work as Child of ColoumnLayoutas there will be few more elements inside ColoumnLayout
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
color: "#18d28a"
Text {
id: application_instruction
width: 640
text: qsTr("xyxvx dgdgdh dhdgdd dhdgdhhgd dhhhdgd dhdgdg dhdgdh djhddh djddgdhgdh dhdgdhgdgh dhgdgdhj dhdgdghdg dhjdgdgd.")
color: "#000000"
font.pointSize: 12
wrapMode: Text.WordWrap
}
}
What is wrong with ColoumnLayout. Am i missing any property value to set. Please help
Inside a ColumnLayout, width properties are ignored.
Instead set Layout.preferredWidth or Layout.maximumWidth attached properties of the Text element.
If you want an item to fill the width of the ColumnLayout, you can set the Layout.fillWidth attached property to true.
From the Answer given by Mark, we can change qml as given bellow and we can display multi line text.
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
id: application_window
visible: true
width: 640
height: 480
title: qsTr("Hello World")
color: "#18d28a"
ColumnLayout {
id: base_coloumn_layout
width: parent.width
Layout.margins: 10
Text {
id: application_instruction
width: application_window.width
Layout.preferredWidth: application_window.width
text: qsTr("xyxvx dgdgdh dhdgdd dhdgdhhgd dhhhdgd dhdgdg dhdgdh djhddh djddgdhgdh dhdgdhgdgh dhgdgdhj dhdgdghdg dhjdgdgd.")
color: "#000000"
font.pointSize: 12
wrapMode: Text.WordWrap
}
}
}

Qml for ios application is too slow

I am developing an application with Qt and qml and I am building it for OSX, iOS and Android. The application contains a StackView which has only three pages. In the second page I have a five MenuItems and five Dialogs.
While this very simple application has an excellent performance when runs on OSX and Android, it delays up to 3-4 seconds to show the second page on iOS.
I have already tried "Qml Profiler" and I have found out that the delay happens during the creation of the qml file that describes the second page.
I have also tried "Qt Quick Compiler" (Commercial Qt) with no significant difference.
main.qml
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
ApplicationWindow {
id: app
title: "MyApp"
width: 1024
height: 768
visible: true
StackView {
id: stackView
anchors.fill: parent
initialItem: firstPage
}
Component {
id:firstPage
FirstPage {
}
}
}
firstPage.qml
import QtQuick 2.3
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
Item {
id:firstPage
signal collectionClicked(string name)
focus: true
objectName: "firstPage"
Rectangle {
anchors.fill: parent
color: "blue"
}
MouseArea {
anchors.fill: parent
onClicked: {
stackView.push(Qt.resolvedUrl("SecondPage.qml"))
}
}
}
SecondPage.qml
import QtQuick 2.3
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
Item {
id: itemsPage
signal itemClicked()
Rectangle {
id: myRectangle
anchors.fill: parent
color: "red"
Dialog {
id: dialog1
height: 200
width: 300
//onAccepted: ;
}
Dialog {
id: dialog2
height: 200
width: 300
//onAccepted: ;
}
Dialog {
id: dialog3
height: 200
width: 300
//onAccepted: ;
}
Dialog {
id: dialog4
height: 200
width: 300
//onAccepted: ;
}
Dialog {
id: dialog5
height: 200
width: 300
//onAccepted: ;
}
Menu {
id: myMenu
title: "Menu"
MenuItem {
text: "Test"
//onTriggered: ;
}
MenuItem {
text: "Test"
//onTriggered: ;
}
MenuItem {
text: "Test"
//onTriggered: ;
}
MenuItem {
text: "Test"
//onTriggered: ;
}
MenuItem {
text: "Test"
//onTriggered: ;
}
}
}
MouseArea {
anchors.fill: parent
onClicked: stackView.push(Qt.resolvedUrl("ThirdPage.qml"));
}
}
ThirdPage.qml
import QtQuick 2.0
Item {
Rectangle {
anchors.fill: parent
color: "green"
Text {
text: "third page"
}
}
}
I have tried for such a long to find a solution. And I think that it is impossible that there is nobody that has ever tried to make a simple qml application for iOS and faced what I have faced.
Thank you,
Michael

How to Correctly Clear Qml ListView Selection

If I have the following:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
title: qsTr("Hello World")
width: 800
height: 700
visible: true
property var myArray: [1, 2, 3, 4, 5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
menuBar: MenuBar {
Menu {
title: qsTr("&File")
MenuItem {
text: qsTr("&Open")
onTriggered: messageDialog.show(qsTr("Open action triggered"));
}
MenuItem {
text: qsTr("E&xit")
onTriggered: Qt.quit();
}
}
}
Rectangle {
id: myButton
anchors.top: parent.top
anchors.topMargin: 5
color: "yellow"
width: 100
height: 25
radius: 3
anchors.horizontalCenter: parent.horizontalCenter
Text {
text: "Clear Selection"
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
myListView.currentIndex = -1
}
}
}
ListView {
id: myListView
width: 300
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: myButton.bottom
anchors.topMargin: 5
anchors.bottom: parent.bottom
currentIndex: -1
//highlightFollowsCurrentItem: false
highlight: Rectangle {
color: "pink"
radius: 3
width: parent.width - 10
height: 25
//y: myListView.currentItem.y
anchors.horizontalCenter: parent.horizontalCenter
}
clip: true
model: myArray
delegate: Rectangle {
width: parent.width - 10
height: 25
color: "transparent"
border.color: "cyan"
anchors.horizontalCenter: parent.horizontalCenter
Text {
text: myArray[index]
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
}
MouseArea {
anchors.fill: parent
onClicked: myListView.currentIndex = index
}
}
}
MessageDialog {
id: messageDialog
title: qsTr("May I have your attention, please?")
function show(caption) {
messageDialog.text = caption;
messageDialog.open();
}
}
}
When clicking the Clear Selection button I receive the following:
qrc:/main.qml:67: TypeError: Cannot read property of null
qrc:/main.qml:64: TypeError: Cannot read property of null
How can I clear the selection without getting the error? It doesn't appear to crash the application but I have a list view that changes based on another list view selection and the error occurs several times, cluttering up the debug output in Qt Creator. I have noticed this in Qt 5.4 and 5.5
The documentation for ListView says:
An instance of the highlight component is created for each list. The geometry of the resulting component instance is managed by the list so as to stay with the current item, unless the highlightFollowsCurrentItem property is false.
So you don't need to try to manage the position of the highlight item yourself. If you want to position the highlight, create an intermediate parent item instead:
highlight: Item {
Rectangle {
color: "pink"
radius: 3
width: parent.width - 10
height: 25
anchors.horizontalCenter: parent.horizontalCenter
}
}
As for why it happens, it's likely because the highlight item is reparented, leaving it in a state where its parent property is null. You can test this out with the following code:
anchors.horizontalCenter: { print(parent); parent.horizontalCenter }
The problem in general is that if you have a foo, which is supposed to have a bar, then you reference it as foo.bar, however, if foo was not properly initialized, then it cannot have a bar, since it does not exist (yet). In your case it seems that parent is not properly initialized, so it does not have a width and horizontalCenter (in the delegate, maybe), respectively. The solution is to initialize properly the object whose members are to be used, in our case, parent.
I had asked this question over on the Qt forum (https://forum.qt.io/topic/62328/clearing-a-qml-listview-selection) as well, but stack was quicker with a response. Checking the parent value works:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
title: qsTr("Hello World")
width: 800
height: 700
visible: true
property int myMargin: 5
menuBar: MenuBar {
Menu {
title: qsTr("&File")
MenuItem {
text: qsTr("&Open")
onTriggered: messageDialog.show(qsTr("Open action triggered"));
}
MenuItem {
text: qsTr("E&xit")
onTriggered: Qt.quit();
}
}
}
Rectangle {
id: myButton
anchors.top: parent.top
anchors.topMargin: myMargin
color: "yellow"
width: 100
height: 25
radius: 3
anchors.horizontalCenter: parent.horizontalCenter
Text {
text: "Clear Selection"
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
myListView.currentIndex = -1
}
}
}
Rectangle {
width: 300
anchors.top: myButton.bottom
anchors.topMargin: myMargin
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
ListView {
id: myListView
anchors.fill: parent
currentIndex: -1
spacing: 3
highlightMoveDuration: 25
highlight: Rectangle {
width: parent ? parent.width - 10 : 0
height: parent ? 25 : 0
color: "pink"
radius: 3
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined
}
clip: true
model: ListModel {
id: myArray
Component.onCompleted: {
for (var i = 1; i < 46; i++)
append({number: i})
}
}
delegate: Rectangle {
width: parent ? parent.width - 10 : 0
height: parent ? 25 : 0
color: "transparent"
border.color: "cyan"
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined
Text {
text: number
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
myListView.currentIndex = index
}
}
}
}
}
MessageDialog {
id: messageDialog
title: qsTr("May I have your attention, please?")
function show(caption) {
messageDialog.text = caption;
messageDialog.open();
}
}
}

QML - How to send/pass variable from one qml file to other qml file

How to send a variable, or signal between qml files ?
http://i.stack.imgur.com/MChCG.png
Mainwindow -> create a component Item2.qml
MainWindow -> create a component item1.qml
item1.qml -> create a component Item3.qml
Item3.qml -> change/send variable or signal to ItemII.qml(is created in mainwindow) - How ?
Someone could write a small example ?
Example code:
Item1.qml
//Item 1
import QtQuick 2.1
Rectangle {
width: 200
height: 100
color:"red"
Text{
anchors.centerIn: parent
font.pixelSize: 16
text:"Item1"
width:parent.width
horizontalAlignment: Text.AlignRight
color:"white"
}
}
Item2.qml
//Item 2
import QtQuick 2.1
Rectangle {
width: 100
height: 100
color:"blue"
Text{
anchors.centerIn: parent
font.pixelSize: 16
text:"Item2"
color:"white"
}
}
Item3.qml
//Item 3
import QtQuick 2.1
Rectangle {
id:item3
width: item3Area.pressed?90:100
height: item3Area.pressed?90:100
color:"green"
signal superAwesomeSignal(string txt)
Text{
anchors.centerIn: parent
font.pixelSize: 16
text:"Item3"
color:"white"
}
MouseArea{
id:item3Area
anchors.fill: parent
onClicked:item3.superAwesomeSignal("Hello, from Item 3 ")
}
}
Main.qml
//Main.qml
import QtQuick 2.0
Rectangle {
width: 360
height: 360
Item1{
anchors.top: parent.top
anchors.left: parent.left
Item3{
id:item3
anchors.top: parent.top
onSuperAwesomeSignal: item2.item3SignalReceived(txt)
}
}
Item2{
id:item2
anchors.bottom: parent.bottom
signal item3SignalReceived(string txt)
onItem3SignalReceived:console.debug(txt)
}
}