问题
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
*/
}
回答1:
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()
}
}
回答2:
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.
回答3:
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.
回答4:
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.
来源:https://stackoverflow.com/questions/49178542/filedialog-in-qml-not-working-in-release