Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML Settings errors



  • Hi all,
    I'm trying to do this example.

    The problems are:
    1- I get these two errors when running the app:

    file:///D:/Qt/5.12.3/mingw73_64/qml/QtQuick/Dialogs/DefaultFileDialog.qml:102:33: QML Settings: Failed to initialize QSettings instance. Status code is: 1

    file:///D:/Qt/5.12.3/mingw73_64/qml/QtQuick/Dialogs/DefaultFileDialog.qml:102:33: QML Settings: The following application identifiers have not been set: QVector("organizationName", "organizationDomain")

    2- Also, when I set QQuickStyle::setStyle("Fusion"); in main.cpp, an error says: 'QQuickStyle' has not been declared, and when I include that header file, another error says: 'QQuickStyle: No such file or directory #include <QQuickStyle>'.

    Why are there theses errors, please!?



  • To use QQuickStyles you should add QT += quickcontrols2 to your .pro file.
    For 1st error try to set proper app variables at main.cpp after app has been constructed:

    QGuiApplication app(argc, argv);
        
    app.setOrganizationName("somename");
    app.setOrganizationDomain("somename");
    ...
    


  • @IntruderExcluder

    Thank you.

    That was new for me. I had not used app.setOrganizationName/Domain ect. Why are they needed please?

    And now the problems are solved, no error and it works well. I only get this message in the Application Output, which is not an error, but rather curious why: Model size of -30 is less than 0

    Another question is: thus far I've used QtQuickControls in QML apps but never had to set the line QT += quickcontrols2 in the .pro file. why have I to in this project?



  • @tomy said in QML Settings errors:

    That was new for me. I had not used app.setOrganizationName/Domain ect. Why are they needed please?

    It is used to configure where QSettings where it should persist its data: (see the "Basic usage" section in https://doc.qt.io/qt-5/qsettings.html#details).

    Another question is: thus far I've used QtQuickControls in QML apps but never had to set the line QT += quickcontrols2 in the .pro file

    You probbaly never accessed any QQC2 functionality from the C++ side before, did you? If you only use it at run time (by using it in your QML files) it should work as long as the necessary files are actually installed.


  • Lifetime Qt Champion

    @tomy said in QML Settings errors:

    Another question is: thus far I've used QtQuickControls in QML apps but never had to set the line QT += quickcontrols2 in the .pro file. why have I to in this project?

    You can easily find the answer in the documentation (https://doc.qt.io/qt-5/qquickstyle.html):

    Header:	#include <QQuickStyle>
    qmake:	QT += quickcontrols2
    

    QQuickStyle is C++ and for that you need QT += ...


Log in to reply