Results 1 to 7 of 7

Thread: lookup table

  1. #1
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default lookup table

    what do you think is an efficient way of implementing a lookup table in c++

    i'd use a vector or some other safe container, except calling push_back 400 times seems ridiculous.....

    and i've currently got it as a cstyle array, but that is giving me weirrrrrrrrd results....

    Qt Code:
    1. class LookupTable: public QWidget
    2. {
    3. public:
    4. LookupTable();
    5. int lookupElectrodeNumber(int i);
    6. private:
    7. int base_filter[21][13];
    8. int id_filter[13][21];
    9. int number_to_filter [100];
    10. };
    11. #endif//LOOKUP_TABLE_
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. LookupTable::LookupTable()
    2. {
    3.  
    4. int::number_to_filter[] = { blah blah blah....a heck of a lot of numbers};
    5.  
    6. }
    7.  
    8. int LookupTable::lookupElectrodeNumber(int i)
    9. {
    10. return number_to_filter[i];
    11. }
    To copy to clipboard, switch view to plain text mode 

    seems simple....but gives wacky stuff....

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: lookup table

    First of all cut this code
    Qt Code:
    1. int base_filter[21][13];
    2. int id_filter[13][21];
    To copy to clipboard, switch view to plain text mode 
    if its not actual

    Then show how do you init your vector,how do you call method lookupElectrodeNumber and what his retturn ?
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: lookup table

    Quote Originally Posted by georgie
    LookupTable::LookupTable()
    {

    int::number_to_filter[] = { blah blah blah....a heck of a lot of numbers};

    }
    You create a local variable, instead of initializing the number_to_filter member variable.

    Does the contents of base_filter, id_filter and number_to_filter change?

  4. #4
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: lookup table

    no....it's pre defined (for a weird numbering system of nodes which goes in a quasi hexagonal fashion) and won't change

  5. #5
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: lookup table

    How about using QMap class?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: lookup table

    How about a global static predefined array?

    Qt Code:
    1. static int base_filter[21][13] = { {1...21}, {22...42}, ...};
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 12th May 2006 at 08:02.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: lookup table

    Quote Originally Posted by wysota
    How about a global static predefined array?
    I would do it this way:
    Qt Code:
    1. namespace
    2. {
    3. const int base_filter[21][13] = { { 1, ..., 21 }, { 22, ..., 42 }, ... };
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 17:18
  2. Replies: 3
    Last Post: 5th October 2008, 23:41
  3. how to add sub table to QSqlRelationalTableModel
    By SunnySan in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2008, 11:05
  4. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  5. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50

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.