Results 1 to 3 of 3

Thread: QHash only getting updated not populated

  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QHash only getting updated not populated

    hello everybody
    here is sample of code. Problem with it is only latest element read and appended to hash exists. previous donot.
    Qt Code:
    1. struct dataStruct
    2. {
    3. int id[15];
    4. int x[15], y[15];
    5. };
    6. //mData is of type dataStruct a data member of MyThread
    7. void MyThread::run()
    8. {
    9. int count,timesOfRead=0,i=0;
    10. int fd0 = open("/home/prince/mydev01",O_RDWR|O_NONBLOCK);
    11. if(fd0== -1)
    12. cout<<"\n------------------- No fifo found///////---------------------\n\n";
    13. else
    14. cout<<" Fifo found \n";
    15.  
    16. // iterator for iterating over hash
    17. QHashIterator<int, QList<float> *> itr(hash);
    18. bool mthFlag=false;// this is here to check whether itr fond element or not
    19. QList<float> * tempList;
    20. while( ! _end )
    21. {
    22.  
    23. while((count=read(fd0 ,&mData,sizeof(struct dataStruct))!=-1))
    24. {
    25. cout<<"\n no of bytes read"<<count<<"\t"<< count/sizeof(struct dataStruct);
    26.  
    27. for(i=0;i<15;i++)//for loop1- for each id of structure
    28. {itr.toFront();
    29. while(itr.hasNext())
    30. {
    31. itr.next();
    32. if(itr.key()==mData.id[i]) // if id exist add it to the list
    33. {
    34. itr.value()->append(mData.x[i]);
    35. itr.value()->append(mData.y[i]);
    36. mthFlag=true; // id found
    37. break;//no need to iterate remaining has
    38. }
    39.  
    40. }
    41.  
    42. if(mthFlag!=true)
    43. {
    44. tempList=new QList<float>;
    45. tempList->append(mData.x[i]);
    46. tempList->append(mData.y[i]);
    47. hash.insert(mData.id[i],tempList);// hash is data member of MyThread class
    48.  
    49. }
    50. mthFlag=false;
    51. }//for-loop1
    52.  
    53. itr.toFront();
    54. while ( itr.hasNext())
    55. { itr.next();
    56.  
    57. QListIterator<float> tempListItr(*itr.value());
    58. tempListItr.toBack();
    59. while(tempListItr.hasPrevious())
    60. cout<<" "<<tempListItr.previous();
    61. cout<<"\t";
    62. }
    63.  
    64.  
    65. itr.toFront();
    66. emit dataAvailable();
    67. _semaphore.acquire();
    68. }}
    69. close(fd0);
    70. emit stopThreadSignal();
    71. cout<<"\tdataAvailable called";
    72.  
    73. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 13th July 2006 at 11:30. Reason: post date has been changed to restore thread order

  2. #2
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QHash only getting updated not populated

    i couldn't get it

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHash only getting updated not populated

    Quote Originally Posted by quickNitin
    i couldn't get it
    We had problems with time on the server, so your post looked like if was posted nine months ago.

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.