Results 1 to 6 of 6

Thread: Get string buy its number

  1. #1
    Join Date
    Mar 2010
    Posts
    38
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Get string buy its number

    Ok i need something like database but small. For examle i have 5 strings which have their own uniq id.
    And if request id it must give me a string wich connected with this id.

    Somethin like:
    list->addVar(1,"blah1');
    list->addVar(5,"blah2");

    list->requeststring(5); and it returns "blah2"

    and if we have added list->addVar(5,"blah2"); one time and then another time like
    list->addVar(5,"blah3"); it will replace old "blah2" with new "blah3" string

    so what object must i use in this case??

  2. #2
    Join Date
    Sep 2010
    Posts
    145
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get string buy its number

    Tried QMap<int, QString> or std::map<int, string>?

  3. #3
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get string buy its number

    If it is small, then maybe an array would be the way to go!

  4. #4
    Join Date
    Mar 2010
    Posts
    38
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Get string buy its number

    I have read abowt QMap and it is exactly what i want)

    But here is a problem:

    Qt Code:
    1. void MainWindow::textChanged(QString textch)
    2. {
    3. //At first we are finding index of our element
    4. int lineidx = tabWidget->currentIndex();
    5. //Then adding item in QMap using lineidx varieble as key and textch as value (maybe i do something wrong because after qDebug()<< linemap.value(index); it returns nothing!
    6. linemap[lineidx]= textch;
    7. }
    To copy to clipboard, switch view to plain text mode 

    What wrong??

  5. #5
    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: Get string buy its number

    in:
    linemap.value(index)

    does index exist in the map?

  6. #6
    Join Date
    Mar 2010
    Posts
    38
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Get string buy its number

    Index is an variable which must exist in map if linemap[lineidx]= textch; is right way to add value in map)

Similar Threads

  1. Replies: 1
    Last Post: 22nd July 2010, 17:12
  2. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  3. how to format a number into a const width string ?
    By lovelypp in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 21:45
  4. Int to String - manipulating string
    By mickey in forum General Programming
    Replies: 6
    Last Post: 5th November 2007, 20:11
  5. Converting number to string.
    By safknw in forum Newbie
    Replies: 2
    Last Post: 18th September 2006, 12:12

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.