Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. What is your suggestion?

What is your suggestion?

Scheduled Pinned Locked Moved C++ Gurus
10 Posts 5 Posters 2.8k Views
  • 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.
  • A Offline
    A Offline
    Armin
    wrote on last edited by
    #1

    Hi
    I need help saving data ,
    I want to save numbers data that are in dates ,
    and then extract this data later.
    for example :
    i had saved some numbers , now i want check to see what day was best in a year.
    What is your suggestion?
    Thanks.

    Paul ColbyP 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please give an example of what you are trying to save/reload.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Armin
        wrote on last edited by
        #3

        Thanks @SGaist

        Look:

        2016-11-25 500
        2016-11-26 450
        2016-11-27 200
        2016-11-28 300
        2016-11-29 1000
        .
        .
        .
        2016-12-25 100
        2016-12-26 125
        2016-11-27 700
        2016-12-28 300
        2016-12-29 600

        2016-11-29 is most and equal 1000
        How can i store data like above ?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          A text file or a CSV file. Depending on what you want to do with these data a SQLite database might be a good alternative.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • A Offline
            A Offline
            Armin
            wrote on last edited by
            #5

            @SGaist Thanks
            Do u suggest SQL?
            you mean writing this program without sql is illogical?

            jsulmJ 1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              SQLite is just a file format at the end of the day. You can use what you want, even xml is an option. If you have a large amount of data and need to perform sql-like operations on it then SQLite is probably the best option

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              3
              • A Armin

                @SGaist Thanks
                Do u suggest SQL?
                you mean writing this program without sql is illogical?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Armin No, he did not. He just said that QSQLite could be an option depending on your requirements. And since you know your requirements you should decide whether SQLite is a good solution.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                3
                • A Offline
                  A Offline
                  Armin
                  wrote on last edited by
                  #8

                  Thanks
                  In fact i am beginner and i don't want use and learn SQL or database and i think is better if focus on C++ .
                  However don't any way for me without lean SQL ?
                  Thanks

                  1 Reply Last reply
                  0
                  • A Armin

                    Hi
                    I need help saving data ,
                    I want to save numbers data that are in dates ,
                    and then extract this data later.
                    for example :
                    i had saved some numbers , now i want check to see what day was best in a year.
                    What is your suggestion?
                    Thanks.

                    Paul ColbyP Offline
                    Paul ColbyP Offline
                    Paul Colby
                    wrote on last edited by
                    #9

                    @Armin said:

                    I want to save numbers data that are in dates, and then extract this data later.
                    ...
                    2016-11-25 500
                    2016-11-26 450
                    ...

                    Here's an example... just one way to do it.

                        // Some data.
                        QMap<QDate, int> values;
                        values.insert(QDate(2016, 11, 25), 500);
                        values.insert(QDate(2016, 11, 26), 450);
                        values.insert(QDate(2016, 11, 27), 200);
                        values.insert(QDate(2016, 11, 28), 300);
                        values.insert(QDate(2016, 11, 29), 1000);
                        values.insert(QDate(2016, 12, 25), 100);
                        values.insert(QDate(2016, 12, 26), 125);
                        values.insert(QDate(2016, 11, 27), 700);
                        values.insert(QDate(2016, 12, 28), 300);
                        values.insert(QDate(2016, 12, 29), 600);
                    
                        // Write to file.
                        QFile file(QLatin1String("temp.txt"));
                        if (file.open(QFile::WriteOnly)) {
                            QTextStream stream(&file);
                            for (auto iter = values.constBegin(); iter != values.constEnd(); ++iter) {
                                stream << iter.key().toString(Qt::ISODate) << ' '
                                       << QString::number(iter.value()) << '\n';
                            }
                        }
                        file.close();
                    
                        // Read from file
                        QMap<QDate, int> readValues;
                        if (file.open(QFile::ReadOnly)) {
                            QTextStream stream(&file);
                            while (!stream.atEnd()) {
                                const QStringList parts = stream.readLine().split(QLatin1Char(' '));
                                const QStringList dateParts = parts.at(0).split(QLatin1Char('-'));
                                const QDate date = QDate(dateParts.at(0).toInt(),
                                                         dateParts.at(1).toInt(),
                                                         dateParts.at(2).toInt());
                                readValues.insert(date, parts.at(1).toInt());
                            }
                        }
                    
                        qDebug() << values;
                        qDebug() << readValues;
                        qDebug() << (readValues == values);
                    

                    This writes, then reads a file containing:

                    2016-11-25 500
                    2016-11-26 450
                    2016-11-27 700
                    2016-11-28 300
                    2016-11-29 1000
                    2016-12-25 100
                    2016-12-26 125
                    2016-12-28 300
                    2016-12-29 600
                    

                    And also outputs (in debug):

                    QMap((QDate("2016-11-25"), 500)(QDate("2016-11-26"), 450)(QDate("2016-11-27"), 700)(QDate("2016-11-28"), 300)(QDate("2016-11-29"), 1000)(QDate("2016-12-25"), 100)(QDate("2016-12-26"), 125)(QDate("2016-12-28"), 300)(QDate("2016-12-29"), 600))
                    QMap((QDate("2016-11-25"), 500)(QDate("2016-11-26"), 450)(QDate("2016-11-27"), 700)(QDate("2016-11-28"), 300)(QDate("2016-11-29"), 1000)(QDate("2016-12-25"), 100)(QDate("2016-12-26"), 125)(QDate("2016-12-28"), 300)(QDate("2016-12-29"), 600))
                    true
                    

                    Cheers.

                    1 Reply Last reply
                    7
                    • A Offline
                      A Offline
                      Armin
                      wrote on last edited by
                      #10

                      @Paul-Colby Wow , Thanks for share , Your answer is fantastic

                      But I'm beginner and understanding your code is hard for me
                      I think input or output in Qt is difference with C++
                      Can i ask a question which what is name of your method writed code?
                      Thanks

                      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