I have the following scenario:
- Data from multiple video file开发者_开发问答s needs to be held in a data structure/collection.
- A video file can have 1 to many video streams.
- Each stream has a field and value pair.
For example:
Video1:
Stream1:
format mpeg
bitrate 700kb/s
resolution 1024x764
Stream2:
format mpeg
bitrate 600kb/s
resolution 800x600
Video2:
Stream1:
format mpeg
bitrate 700kb/s
resolution 1024x764
Stream2:
format mpeg
bitrate 600kb/s
resolution 800x600
This is what I was consider holding the data in:
QVector<QVector<QStringList>>
Where QStringList
are the value pairs (format, mpeg).
Inside QVector
holds the multiple pairs for the stream.
Outside QVector
holds the everything i.e. each entry/index is data for a single video file.
I'm not sure whether this is the best way to hold the data a I guess a collection inside a collection inside a collection is not going to be very efficient.
Any opinions on alternatives?
Why not write classes as you need?
class Stream
{
Format format;
Resolution res;
Bitrate br;
};
class Video
{
QVector<Stream> v_stream;
};
class VideoContainer
{
QVector<Video> v_video;
};
QVector required to continuous location of data such as classical C-array. For general purposes recommended QList instead of QVector which also provides fast index-based access but based on pointers.
For field-value pairs use QMap instead of StringList, thst would be easier to access. Maybe even QMap<QString,QVariant>
or QMap<QString,QString>
if you use only text properties.
Also, as triclosan said, use QList
instead of QVector
. So final look would be QList<QList<QMap< QString,QVariant > > >
精彩评论