Results 1 to 2 of 2

Thread: qstring.mid() questions

  1. #1
    Join Date
    Dec 2010
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qstring.mid() questions

    Ok, I can't figure out why this is not working:


    Qt Code:
    1. QString temp_vol_id = temp_string;
    2. int first_dot = temp_string.indexOf(".");
    3. int last_dot = temp_string.lastIndexOf(".");
    4. QString temp_name = temp_string.mid((first_dot+1),((last_dot-first_dot)-1))
    To copy to clipboard, switch view to plain text mode 

    where temp_vol_id = a valid 82 char qstring
    first_dot = 47
    last_dot = 61

    the debugger states temp_name is <invalid>
    I attempted changing qstring.mid second parameter to -1 (it should extract from
    first_dot to end of string, but that also returns <invalid>

    I am using similar statements in other sections of the code successfully.
    Can anyone see anything incorrect in this snippet of code?

    thanks

    John


    Added after 5 minutes:


    I should have included the complete function for clarity:

    Qt Code:
    1. QString Widget::get_Vol_ID(QString temp_string)
    2. {
    3. QString temp_vol_id = temp_string;
    4. int first_dot = temp_vol_id.indexOf(".");
    5. int last_dot = temp_vol_id.lastIndexOf(".");
    6. QString temp_name1 = temp_vol_id.mid((first_dot+1),((last_dot-first_dot)-1));
    7. // QString temp_name = temp_vol_id.mid(first_dot,-1);
    8. // QString temp_name = temp_vol_id.mid((first_dot+1),((last_dot-first_dot)-1));
    9. QString temp_noise = "";
    10. return(temp_name1);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    you can see the commented out lines that were attempted (without success)

    thanks

    John
    Last edited by Lykurg; 6th February 2011 at 17:33. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: qstring.mid() questions

    Hm, there is no error in the code. It works well on my side. Please add
    Qt Code:
    1. qWarning() << Q_FUNC_INFO << temp_vol_id << first_dot << last_dot;
    To copy to clipboard, switch view to plain text mode 
    before the return of your function and post the output in the cases where it do not work like expected.

Similar Threads

  1. Replies: 8
    Last Post: 25th November 2010, 11:40
  2. With QString create a QString&
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 21st April 2010, 22:05
  3. Replies: 4
    Last Post: 1st February 2010, 14:21
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. how to copy part of QString to anothe QString
    By nass in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2007, 19:05

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.