PDA

View Full Version : QHash only getting updated not populated



quickNitin
12th July 2006, 23:00
hello everybody
here is sample of code. Problem with it is only latest element read and appended to hash exists. previous donot.


struct dataStruct
{
int id[15];
int x[15], y[15];
};
//mData is of type dataStruct a data member of MyThread
void MyThread::run()
{
int count,timesOfRead=0,i=0;
int fd0 = open("/home/prince/mydev01",O_RDWR|O_NONBLOCK);
if(fd0== -1)
cout<<"\n------------------- No fifo found///////---------------------\n\n";
else
cout<<" Fifo found \n";

// iterator for iterating over hash
QHashIterator<int, QList<float> *> itr(hash);
bool mthFlag=false;// this is here to check whether itr fond element or not
QList<float> * tempList;
while( ! _end )
{

while((count=read(fd0 ,&mData,sizeof(struct dataStruct))!=-1))
{
cout<<"\n no of bytes read"<<count<<"\t"<< count/sizeof(struct dataStruct);

for(i=0;i<15;i++)//for loop1- for each id of structure
{itr.toFront();
while(itr.hasNext())
{
itr.next();
if(itr.key()==mData.id[i]) // if id exist add it to the list
{
itr.value()->append(mData.x[i]);
itr.value()->append(mData.y[i]);
mthFlag=true; // id found
break;//no need to iterate remaining has
}

}

if(mthFlag!=true)
{
tempList=new QList<float>;
tempList->append(mData.x[i]);
tempList->append(mData.y[i]);
hash.insert(mData.id[i],tempList);// hash is data member of MyThread class

}
mthFlag=false;
}//for-loop1

itr.toFront();
while ( itr.hasNext())
{ itr.next();

QListIterator<float> tempListItr(*itr.value());
tempListItr.toBack();
while(tempListItr.hasPrevious())
cout<<" "<<tempListItr.previous();
cout<<"\t";
}


itr.toFront();
emit dataAvailable();
_semaphore.acquire();
}}
close(fd0);
emit stopThreadSignal();
cout<<"\tdataAvailable called";

}

quickNitin
13th July 2006, 10:54
i couldn't get it

jacek
13th July 2006, 11:32
i couldn't get it
We had problems with time on the server, so your post looked like if was posted nine months ago.