Results 1 to 2 of 2

Thread: QList custom data format

  1. #1

    Default QList custom data format

    Hi,

    I want to use like structure array for 100s of custom data in QList.
    each custom data has name,age. I created a class for custom data. and use that class fr QList container.

    I am using the following code, I am able to store it & retrive it. But i how do i search the QList if it is custom data?

    thanks
    suresh


    class studentt
    {
    public:
    QString name;
    int class1;
    }s[100];

    void initclass()
    {
    for(int i =0;i<100;i++)
    s[i].class1=(i+2)*9;
    s[i].name="test";
    }

    int main(int argc,char *argv[])
    {
    initclass();
    QList<studentt> aa;
    for(int i =0;i<100;i++)
    aa.append(s[i]);

    studentt d;
    for(int i=0;i<100;i++)
    {
    d=aa.at(i);
    qDebug() <<"class1"<<d.class1;
    }
    /////The following line is not working - How do i use search if it is custom data
    //int x=aa.indexOf(900);
    //d=aa.at(x);
    //qDebug() <<"class1"<<d.class1;
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QList custom data format

    Do you want to know if an item is of type "Student" or do you want to search for a specific student in the list?

    If you implement the == operator in your student class, you can simply use QList::contains
    Otherwise do something like this:

    Qt Code:
    1. foreach(const Student &student, aa) {
    2. if (student.name() == "John") {
    3. // found the student
    4. break;
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Qt to Matlab (mat format) export data to Matlab .mat format -v4
    By windsword in forum Qt-based Software
    Replies: 4
    Last Post: 26th February 2013, 20:01
  2. How to export data from QSql classes to XML format
    By behrouz in forum Qt Programming
    Replies: 2
    Last Post: 29th June 2010, 16:04
  3. storing data in hexadecimal format
    By aj2903 in forum Qt Programming
    Replies: 6
    Last Post: 13th January 2010, 05:29
  4. How can you display binary data in hex format?
    By Cruz in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2009, 14:40
  5. Defining data format in c++
    By locus in forum General Programming
    Replies: 3
    Last Post: 13th April 2007, 19:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.