Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

3-dimensional array storage as string



  • 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


  • Qt Champions 2019

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

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


  • 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



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


Log in to reply