Results 1 to 5 of 5

Thread: qstringlist array crashes program

  1. #1
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qstringlist array crashes program

    Can someone explain this
    This works
    Qt Code:
    1. QString usage = "12.34 56.78";
    2. QStringList usage2 = usage.split(" ");
    3. foreach (QString str, usage2) {
    4. qDebug() << str;
    5. }
    To copy to clipboard, switch view to plain text mode 
    This works
    Qt Code:
    1. float used = usage2[0].toFloat();
    To copy to clipboard, switch view to plain text mode 
    This does not work
    Qt Code:
    1. float used = usage2[1].toFloat();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: qstringlist array crashes program

    seems like usage2 is rewritten somewhere

  3. #3
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qstringlist array crashes program

    I tested the code provided and it worked.

    So the error is not coming from these instructions

  4. #4
    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: qstringlist array crashes program

    The space character is probably not the space character but some other whitespace.
    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.


  5. #5
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qstringlist array crashes program

    here is a bit more information
    my programming skills are bad so there is probably a fundamental error somewhere, porbably in the header file but...
    a timer calls a public slot function "update" which reads a file containining a single line of data and assings it to usage
    if i extract the data from usage in this function I can use
    if i extract this data elsewhere it crashes
    .... hmmm just sovlved the problem

    The reason was the variable was empty, I just needed to call the function first

Similar Threads

  1. Program crashes on creating new dialog
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 11:52
  2. wrong connection? program crashes altough it compiles
    By cbarmpar in forum Qt Programming
    Replies: 7
    Last Post: 30th September 2008, 12:48
  3. Program crashes with assert error in xcb_lock.c
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2007, 19:56
  4. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19
  5. Reading from TCP Socket crashes program
    By OnionRingOfDoom in forum Qt Programming
    Replies: 26
    Last Post: 27th January 2006, 19:32

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.