Difference between revisions of "Qt/Utilities/Settings"
From ProgrammingExamples
< Qt
Daviddoria (Talk | contribs) (Created page with '==Settings.cpp== <source lang="cpp"> #include <QtCore> #include <iostream> void LocalUsage(); void GlobalUsage(); int main(int argc, char *argv[]) { QCoreApplication app(arg…') |
(No difference)
|
Latest revision as of 11:32, 18 September 2012
Settings.cpp
#include <QtCore> #include <iostream> void LocalUsage(); void GlobalUsage(); int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); LocalUsage(); GlobalUsage(); return 0; } void LocalUsage() { QSettings settings("MyCompany", "MyProgram"); QString hello = "Hello, world!"; // store a value settings.setValue("Greeting", hello); // creates ~/.config/OpenSourcePress/ConfigTest.conf // reset variable hello = ""; // read value and assign to variable hello = settings.value("Greeting").toString(); std::cout << hello.toStdString() << std::endl; // prints "Hello, world!" } void GlobalUsage() { QCoreApplication::setOrganizationName("MyCompany"); //QCoreApplication::setOrganizationDomain("mysoft.com"); QCoreApplication::setApplicationName("MyProgram"); QSettings settings; QString hello = "Hello, world!"; // store a value settings.setValue("Greeting", hello); // creates ~/.config/OpenSourcePress/ConfigTest.conf // reset variable hello = ""; // read value and assign to variable hello = settings.value("Greeting").toString(); std::cout << hello.toStdString() << std::endl; // prints "Hello, world!" }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(Settings) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) INCLUDE_DIRECTORIES(${QT_QTXML_INCLUDE_DIR}) # Prevents "QtXml: No such file or directory" ADD_EXECUTABLE(Settings Settings.cpp) message(${QT_LIBRARIES}) TARGET_LINK_LIBRARIES(Settings ${QT_LIBRARIES})