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. 3-dimensional array storage as string
Forum Updated to NodeBB v4.3 + New Features

3-dimensional array storage as string

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 941 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.
  • J Offline
    J Offline
    jars121
    wrote on last edited by
    #1

    Hi,

    I have 32 data sets, each containing an array of 20 XY coordinates. I currently have each of the 32 data sets stored in my config.ini file as follows:

    dataSet1=[1, 5],[2,10],[3,15],[4,20],...
    dataSet2=...
    ...
    dataSet32=...
    

    Hopefully you get the picture from the above snippet.

    I've set up a 3-dimensional QVector array in my application as QVector<QVector<QVector<QPointF> >>, with the intention of capturing all 32 data sets in the single array, but I'm unable to capture the .ini values as QPointF values in the array. I've tried converting the dataSetX strings from the .ini file into StringLists first, but I can't seem to find a way to separate the X/Y pairs. The square brackets will need to be removed, but I'm not sure how else to separate the pairs as a string.

    I'm more than happy to entertain/explore other options, but would prefer to leave the data sets as strings in the .ini file for now, rather than storing them elsewhere.

    Many thanks,

    Jamie

    jsulmJ 1 Reply Last reply
    0
    • J jars121

      Hi,

      I have 32 data sets, each containing an array of 20 XY coordinates. I currently have each of the 32 data sets stored in my config.ini file as follows:

      dataSet1=[1, 5],[2,10],[3,15],[4,20],...
      dataSet2=...
      ...
      dataSet32=...
      

      Hopefully you get the picture from the above snippet.

      I've set up a 3-dimensional QVector array in my application as QVector<QVector<QVector<QPointF> >>, with the intention of capturing all 32 data sets in the single array, but I'm unable to capture the .ini values as QPointF values in the array. I've tried converting the dataSetX strings from the .ini file into StringLists first, but I can't seem to find a way to separate the X/Y pairs. The square brackets will need to be removed, but I'm not sure how else to separate the pairs as a string.

      I'm more than happy to entertain/explore other options, but would prefer to leave the data sets as strings in the .ini file for now, rather than storing them elsewhere.

      Many thanks,

      Jamie

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

      @jars121 Why do you need a 3-dimensional vector?

      QString tuple = "[1, 5]";
      QStringList values = tuple.remove('[').remove(']').split(',');
      

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

      VRoninV 1 Reply Last reply
      2
      • jsulmJ jsulm

        @jars121 Why do you need a 3-dimensional vector?

        QString tuple = "[1, 5]";
        QStringList values = tuple.remove('[').remove(']').split(',');
        
        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        You can use regular expressions:

        // QString datasetString = "dataSet1=[1, 5],[2,10],[3,15],[4,20]";
        const QRegularExpression pointsRe(R"**(\[\s*([-+]?\d*\.?\d+)\s*,\s*([-+]?\d*\.?\d+)\s*\])**");
        auto matchesIter =  pointsRe.globalMatch(datasetString);
        while (matchesIter.hasNext()){
        const auto match = matchesIter.next();
        qDebug() << QPointF(match.capturedRef(1).toDouble(),match.capturedRef(2).toDouble());
        }
        

        @jsulm said in 3-dimensional array storage as string:

        Why do you need a 3-dimensional vector?

        i share the question

        "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
        1
        • J Offline
          J Offline
          jars121
          wrote on last edited by
          #4

          Thank you both for your valuable input.

          The desired state is to contain all 20 XY pairs for all 32 data sets in the single array, as follows (using an 8 XY pair, 2 data set array as an illustration):

          array = [[[X1, Y1],[X2, Y2],[X3, Y3],[X4, Y4],[X5, Y5],[X6, Y6],[X7, Y7],[X8, Y8]], [[X1, Y1],[X2, Y2],[X3, Y3],[X4, Y4],[X5, Y5],[X6, Y6],[X7, Y7],[X8, Y8]]]

          My understanding is the above would be a QVector<QVector<QVector<QPointF> >>. I'd rather avoid RegEx if possible, but would certainly like to test the tuples.remove approach further if that's still a recommended method.

          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