Results 1 to 5 of 5

Thread: for data show out of loop

  1. #1
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default for data show out of loop

    for(j=0;j<mylist.length();j++)
    {
    if(mylist[j]=="Anup")
    {
    es3=mylist[j-13];
    arr[j]=es3.toDouble();
    qdebug()<<arr[j];
    }
    }
    i want to show the arr[j] values out of loop i am not able to do. plzz help
    so that i can call arr[j] value any where

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: for data show out of loop

    You don't show enough of your code to answer your question. Where is "arr" declared and what is it's scope for starters?

    I also doubt this code does what you want. You are only assigning arr[j] a value when your mylist[j] is equal to "Anup". All other iterations of this loop won't assign a value to the other values that exit in the j=0 to j < mylist.length() for loop.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: for data show out of loop

    int arr[50];
    QStringlist mylist;
    Qstring es3;

    for(j=0;j<50;j++)
    {
    if(mylist[j]=="Anup")
    {
    es3=mylist[j-13];
    arr[j]=es3.toDouble();
    qdebug()<<arr[j];
    }
    }


    data is coming in the loop but i want out of the loop.

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: for data show out of loop

    What have you tried and what error(s) do you get?

    For starters, you don't initialize "arr" and only assign arr[j] when mylist[j] == "Anup", so of the 50 integers in the arr integer array, only one of them would have a defined value, which can't possibly be what you want.

    Try the following after the end of your loop:
    Qt Code:
    1. int test = arr[0];
    2. qDebug() << "test=" << test;
    To copy to clipboard, switch view to plain text mode 
    That code would access the first item in the integer array named "arr", but will likely be garbage or a random value because you have not initialized the items in the array. I suspect this is not your actual code, because I don't see where you define "j", but assuming it's defined in the actual for statement, then it will be out of scope (inaccessible and invisible) outside of the for loop. Is that what you're asking?

    Show your actual code (using code tags) and try again to explain what it is you are trying to do, what you have tried, and what error(s) you're getting.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  5. #5
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: for data show out of loop

    thanks alot for the help

Similar Threads

  1. Saving data as a .txt file using a for loop
    By VitaminG in forum Newbie
    Replies: 2
    Last Post: 23rd January 2017, 07:46
  2. Show complex cpp data model in QML
    By ms2222 in forum Qt Quick
    Replies: 4
    Last Post: 2nd March 2015, 13:55
  3. Replies: 1
    Last Post: 17th March 2012, 14:05
  4. QTableView does not show data
    By waynew in forum Newbie
    Replies: 4
    Last Post: 12th December 2009, 00:38
  5. how kd chart's data to show tooltip?
    By yunpeng880 in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2009, 07:27

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.