Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Using QSettings from QML

$
0
0
Hello I’m new to the forum and pretty new to QT5 development with QML as well. I’ve got an application using some C++ objects and QML for the GUI. I’m tryng to store values in a .conf file using QSettings. I am creating a settings object my main object: application.h: #include <QSettings>   class RS232VisualizerMain : public QObject {     Q_OBJECT private:       SerialConnect* serialPort;     QSettings* appSettings; }   application.cpp: RS232VisualizerMain::RS232VisualizerMain(QObject *parent) :     QObject(parent) {     appSettings = new QSettings;     appSettings->setValue("main/test","test"); } I can save values from my C-class using the code above. However, I couldn’t figure out how to write settings from the QML code. I’m trying to set the object as a context property and writing to it from qml:     application.cpp:     engine = new QQmlEngine;       //export context properties to qml    engine->rootContext()->setContextProperty("appSettings",appSettings);       component = new QQmlComponent(engine);     component->loadUrl(QUrl("qrc:/qml/main.qml"));     if ( !component->isReady() ) {         qWarning("%s", qPrintable(component->errorString()));         return 1;     }     topLevel = component->create();     window = qobject_cast<QQuickWindow *>(topLevel);     if ( !window ) {         qWarning("Error: Your root item has to be a Window.");         return 1;     }     window->show();   main.qml:     Component.onCompleted: {         appSettings.setValue("serialPort/BAUD", "9600")     } With the setValue statement in QML like this, the application crashes on startup with exit code 0 I’m certainly missing something obvious. Any hint to tutorials, documentation or existing forum threads is appreciated.

Viewing all articles
Browse latest Browse all 13965

Latest Images

Trending Articles



Latest Images