Tag Archives: Qt development

How to Solve QML Settings Error (QML FileDialog)

When we want to use the file dialog box in the interface, we can use the FileDialog component with the following code:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Dialogs 1.3

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("")
    
    Button {
        id:openFile
        text: qsTr("Open the Files")
        backgroundDefaultColor: "#5A6268"
        onClicked:  {
            fileDialog.open()
        }
    }

    FileDialog {
        id: fileDialog
        title: qsTr("Please choose a file")
        nameFilters: ["Photo Files", "Image Files (*.jpg *.png *.gif *.bmp *.ico)", "*.*"]
        onAccepted: {
            _filePath.text = String(fileUrl)
            var filepath = new String(fileUrl)
        }
    }
}

Error Message:

file:///D:/Qt/Qt5.12.6/5.12.6/msvc2017_64/qml/QtQuick/Dialogs/DefaultFileDialog.qml:102:33: QML Settings: Failed to initialize QSettings instance. Status code is: 1
file:///D:/Qt/Qt5.12.6/5.12.6/msvc2017_64/qml/QtQuick/Dialogs/DefaultFileDialog.qml:102:33: QML Settings: The following application identifiers have not been set: QVector("organizationName", "organizationDomain")

 

Solution:
Add a line of code to the main function of main.cpp.

QCoreApplication::setOrganizationName("appName.org");//appName.org can be set at will