Results 1 to 8 of 8

Thread: LookUp table Implementation in Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: LookUp table Implementation in Qt

    Take a look at QHash, you can create a hash table mapping Decimal <-> temperature values, and instead of "if-else" statements simply call:
    Qt Code:
    1. // _hash contains your Decimal <-> temperature table
    2. if( _hash.contains(str) ){
    3. temperatureData.append( _hash.value(str) )
    4. }
    To copy to clipboard, switch view to plain text mode 

    ----
    Edit: looks like Stef was faster

  2. #2
    Join Date
    Dec 2010
    Posts
    41
    Thanks
    12

    Default Re: LookUp table Implementation in Qt

    Hello thank you for the response. I did look at QMap but could't figure out how i should be doing it.. Din't find any example. Can you pls show a small example.

    i will try your method also stampede thank you so much for the example code.

    regards

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: LookUp table Implementation in Qt

    Have you looked at the examples in QMap documentation ?
    You just have to store values from your temperature table in such container ( initialize it once somewhere in the program ).

  4. #4
    Join Date
    Jan 2011
    Location
    Netherlands
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 5 Times in 5 Posts

    Default Re: LookUp table Implementation in Qt

    It's not that hard really. First you populate the lookup table with all keys and values. Then if you want to use it you just ask for the key of a specific value.
    Qt Code:
    1. QMap<QString, QString> lookupTable;
    2.  
    3. // Populate lookup table
    4. lookupTable.insert("-40", "289");
    5. lookupTable.insert("-39", "292");
    6. lookupTable.insert("-38", "294");
    7. lookupTable.insert("-37", "296");
    8. lookupTable.insert("-36", "299");
    9. lookupTable.insert("-35", "301");
    10. // ... And so on
    11.  
    12. // Use it
    13. temperaturedata.append(lookupTable.value(str));
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Stef for this useful post:

    rex (9th February 2011)

  6. #5
    Join Date
    Dec 2010
    Posts
    41
    Thanks
    12

    Default Re: LookUp table Implementation in Qt

    thanks a lot i will do it now.. You made it look so easy.

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

    Default Re: LookUp table Implementation in Qt

    Qt Code:
    1. QHash<int,int> lookUp;
    2. lookup[-40] = 289;
    3. lookup[-39] = 292;
    4. // etc.
    To copy to clipboard, switch view to plain text mode 

    or using a static C array:
    Qt Code:
    1. int valueFor(int v) {
    2. static int lookup[] = { 289, 292, 294, ... };
    3. return lookup[v+40];
    4. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    rex (9th February 2011)

Similar Threads

  1. Image resource lookup in OS X
    By stipa in forum Qt Quick
    Replies: 1
    Last Post: 1st December 2010, 09:11
  2. symbol lookup error
    By knishaq in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2010, 16:22
  3. QT-Embedded Symbol Lookup Error
    By augusbas in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 23rd June 2009, 06:01
  4. Dynamic lookup problem
    By jwintz in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2006, 15:19
  5. lookup table
    By georgie in forum General Programming
    Replies: 6
    Last Post: 12th May 2006, 10:57

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
  •  
Qt is a trademark of The Qt Company.