1 year ago
#201508
adam
how to properly declare a qvariantlist and initialize it so i can put my custom object/class into it by appending
i cannot figure out how to use a qvariantlist from all the examples i find i need to stuff filenames-sizes-checksum for multiple files in a csv file and be able to search through them later here is the part where i'm stuck
QVariantList vlFiles;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return vlFiles;
while (!file.atEnd()) {
QByteArray line = file.readLine();
QList<QByteArray> query = line.split(';');
struct information i1;
i1.fileName = query.at(0);
i1.fileSize = query.at(1);
QString ts = query.at(2);
ts.replace("\n", "");
i1.md5Sum = ts;
vlFiles.append(i1)//stuck here
mainwindow.cpp:452:21: error: no matching member function for call to 'append'
qlist.h:204:10: note: candidate function not viable: no known conversion from 'struct information' to 'const QVariant' for 1st argument
qlist.h:205:10: note: candidate function not viable: no known conversion from 'struct information' to 'const QList<QVariant>' for 1st argument
Thanks to Igor's suggestion I was able to get past this point but now I want to retrieve the data back from the qvariantlist and display each item and its 3 sub strings which are saved as a custom struct class...
QVariantList vlFilesToDownload =
getDownloadList("downloadlist.txt");
for(QVariantList::const_iterator it =
vlFilesToDownload.begin();
it!=vlFilesToDownload.end();
++it)
{
if(it->)
part i'm stuck on, i have tried all the options from the auto complete menu and cannot get any useful data from the iterator, i must have to somehow cast the iterator to the QVariantList and my struct class pulls hair out
{
//use qdebug to print the list items and data to console
}
};
c++
qt
qvariant
0 Answers
Your Answer