Containers



  • What is the best container class to use for storing 3 instances of QLists? 3 derived classes from a base class that is implemented with the singleton design pattern, each creating a QList.


  • Moderators

    QList [3], std::tuple, QList, QVector...
    Basically anything with constant access time. For 3 items it doesn't really matter unless you have some more specific requirements like memory constraint or binary layout etc.



  • So you are saying I should store the QLists within a QList(3)? And you would access them by referring to the number? 1,2,3 or 0,1,2?


  • Moderators

    It's a plain C++ array. Like in most other places in C++ indices are 0-based
    An example:
    @
    QList<QString> data[3]; //3 lists of strings
    data[0] << "foo" << "bar"; //add "foo" and "bar" to first list
    qDebug() << data[0][0]; //print first element of first list
    @



  • great thanks for the help.


Log in to reply