Seeking for a solution faster than making databases,not familiar enough with Qsettings and Qsessionmanager,in order to save all the inputs given?
-
have you tried QTextStream or QDataStream? both provided with the solution to save your time by stream reading and writing ability. the only matter you should be care about due to the stream way of pushing and popping, data would be accessible by same order. so you might consider making assist functions in order to save and restore your data.
-
TanQ but as I said I
ve searched a lot about it and know these two names,Qsetting and Qtextstream in Qfiles, but don
t know how to use it,how to save a combobox choice or radiobutton choice in a text file!!!? isnt there a way to save the whole things automatically? since there
s no efficient and useful example like of mine in Qassisstant Please answer a bit more sensible with some codes to do it.... -
Did you really see the QSettings description in Qt SDK? The example code is too clear!!
Basic UsageWhen creating a QSettings object, you must pass the name of your company or organization as well as the name of your application. For example, if your product is called Star Runner and your company is called MySoft, you would construct the QSettings object as follows:
@
QSettings settings("MySoft", "Star Runner");
@
QSettings objects can be created either on the stack or on the heap (i.e. using new). Constructing and destroying a QSettings object is very fast.If you use QSettings from many places in your application, you might want to specify the organization name and the application name using QCoreApplication::setOrganizationName() and QCoreApplication::setApplicationName(), and then use the default QSettings constructor:
@
QCoreApplication::setOrganizationName("MySoft");
QCoreApplication::setOrganizationDomain("mysoft.com");
QCoreApplication::setApplicationName("Star Runner");
...
QSettings settings;
@
(Here, we also specify the organization's Internet domain. When the Internet domain is set, it is used on Mac OS X instead of the organization name, since Mac OS X applications conventionally use Internet domains to identify themselves. If no domain is set, a fake domain is derived from the organization name. See the Platform-Specific Notes below for details.)QSettings stores settings. Each setting consists of a QString that specifies the setting's name (the key) and a QVariant that stores the data associated with the key. To write a setting, use setValue(). For example:
@
settings.setValue("editor/wrapMargin", 68);
@
If there already exists a setting with the same key, the existing value is overwritten by the new value. For efficiency, the changes may not be saved to permanent storage immediately. (You can always call sync() to commit your changes.)You can get a setting's value back using value():
@
int margin = settings.value("editor/wrapMargin").toInt();
@[Edit: Added @ code wrappers -- mlong]
-
I really thank you for your attention but honestly i had read this before but the problema still exist :(
ok,now where the Qsetings with its data in it is saved and how to access it ,as i said for each session user runs the program and gives different input and data ,one file should be created in order to make him load each one he wants in next session helping him now give the inputs and data again for the second time.....the goal is to avoid inputting repetitive data!!! -
QSetting store datas in registry under Microsoft windows. If you want to access the data you just call the QSetting's value function. If each person have one setting , I don't think QSettings is a good choice. Try to write the datas which user input to one file ,you can use QFile, Just call QFile's open, write. read. You also can use the QDatabase to restore every person's data.
-
"QDataStream":http://doc.qt.nokia.com/4.7-snapshot/qdatastream.html#details is actually quite easy to use. Just pass a QFile and push the data as needed; combine it with a bit of introspection and you'll end up with serialization in just a few lines of code.
@
void saveState(QWidget *widget, const QString &fileName)
{
QFile stateFile(fileName);
if (stateFile.open(QIODevice::WriteOnly | QIODevice::Truncate) == true)
{
QDataStream stateStream(&stateFile);
foreach (const QWidget childWidget, widget->findChildren<QWidget>())
{
if (childWidget->property("serializable").toBool() == true)
stateStream << childWidget->objectName()
<< childWidget->metaObject()->userProperty().read(childWidget);
}
}
}void restoreState(QWidget *widget, const QString &fileName)
{
QFile stateFile(fileName);
if (stateFile.open(QIODevice::ReadOnly) == true)
{
QDataStream stateStream(&stateFile);
while (stateStream.atEnd() == false)
{
QString name;
QVariant value;stateStream >> name >> value; QWidget *childWidget = widget->findChild<QWidget*>(name); if ((childWidget != 0) && (childWidget->property("serializable").toBool() == true)) { childWidget->metaObject()->userProperty().write(childWidget, value); } } }
}
@
Brain to terminal. -
[quote author="henryxuv" date="1345511421"]QSetting store datas in registry under Microsoft windows. If you want to access the data you just call the QSetting's value function. If each person have one setting , I don't think QSettings is a good choice.[/quote]
On a sidenote: QSettings "does not neccessarily":http://qt-project.org/doc/qt-4.8/qsettings.html#Format-enum store the settings in the registry; it is just the default behaviour. It is very well suited to store values for "different users":http://qt-project.org/doc/qt-4.8/qsettings.html#Scope-enum, as well as storing "multiple versions":http://qt-project.org/doc/qt-4.8/qsettings.html#QSettings-4. -
Yes, but if you have a question please create your own discussion, or, if it is related to an "already existing discussion":http://qt-project.org/forums/viewthread/19603/, raise your question there.