Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Seeking for a solution faster than making databases,not familiar enough with Qsettings and Qsessionmanager,in order to save all the inputs given?
Forum Updated to NodeBB v4.3 + New Features

Seeking for a solution faster than making databases,not familiar enough with Qsettings and Qsessionmanager,in order to save all the inputs given?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 3.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    henryxuv
    wrote on last edited by
    #2

    Try QSetting , a very simple and useful class.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mohsen
      wrote on last edited by
      #3

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        amin
        wrote on last edited by
        #4

        TanQ but as I said Ive searched a lot about it and know these two names,Qsetting and Qtextstream in Qfiles, but dont 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 theres no efficient and useful example like of mine in Qassisstant Please answer a bit more sensible with some codes to do it....

        1 Reply Last reply
        0
        • H Offline
          H Offline
          henryxuv
          wrote on last edited by
          #5

          Did you really see the QSettings description in Qt SDK? The example code is too clear!!
          Basic Usage

          When 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]

          1 Reply Last reply
          0
          • A Offline
            A Offline
            amin
            wrote on last edited by
            #6

            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!!!

            1 Reply Last reply
            0
            • H Offline
              H Offline
              henryxuv
              wrote on last edited by
              #7

              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.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #8

                "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.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #9

                  [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.

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    henryxuv
                    wrote on last edited by
                    #10

                    Thanks, I got it. The QSettings is powerful than what I supposed. Are you familia with QTcpSocket? Lukas.

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lgeyer
                      wrote on last edited by
                      #11

                      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.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved