Results 1 to 3 of 3

Thread: Convertion from Qstring to int

  1. #1
    Join Date
    Aug 2014
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Convertion from Qstring to int

    I have a Qstring ORBString = "nFeatures=2000, scaleFactor=1.2, nLevels=8, EdgeThreshold=31, Firstlevel=0, WTA_K=2, ScoreType=0 , PatchSize=31";
    Then I use QstringList ORBLists = ORBString.split(",", QString::SkipEmptyParts);
    bool ok;
    int nFeatures = ORBLists.at(0).toInt(&ok,10); // it gives only 0 not 2000

  2. #2
    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: Convertion from Qstring to int

    "nFeatures=2000" is definitely not a number so trying to convert it to int will yield 0 and will raise the error flag (your "ok" variable will be set to false).
    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.


  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Convertion from Qstring to int

    ...and "ok" is set to false as I guess, becaue you can't convert "nFeatures=2000" to int. You can convert "2000" to int, so you have to extract this number from this string (use another split() or mid() or whatever function you find most convenient to you) and then, when you have string "2000", call toInt() on it.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. The following user says thank you to faldzip for this useful post:

    urmila (27th August 2014)

Similar Threads

  1. IPC- char * to WCHAR* convertion?
    By Ricardo_arg in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2010, 18:55
  2. Convertion from QString to unsigned char *
    By vcp in forum Qt Programming
    Replies: 5
    Last Post: 13th August 2010, 18:26
  3. QString to double convertion problem
    By NoRulez in forum Qt Programming
    Replies: 3
    Last Post: 9th July 2010, 18:48
  4. Time convertion
    By rajeshs in forum Qt Programming
    Replies: 3
    Last Post: 5th June 2008, 11:22

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.