0

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
    } 
}; 
adam
  • 67
  • 8
  • 1
    Try `vlFiles.append(QVariant::fromValue(i1));` Your structure must have its metadata registered with [`Q_DECLARE_METATYPE`](https://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE) – Igor Tandetnik Feb 20 '22 at 05:10
  • Got that working, thank you for that Igor, any idea how to cast an item from the qvariantlist back to my custom class that contains a struct with 3 QStrings for data? – adam Feb 20 '22 at 06:57
  • 1
    `vlFiles.first().value()` – Igor Tandetnik Feb 20 '22 at 13:55
  • Not sure why the other person deleted their extensive comment, I just went to go over it and its been removed, it looked like a juicy answer too, thats a dissappointment should have left it – adam Feb 21 '22 at 00:48

0 Answers0