PDA

View Full Version : Application is fully functional ONLY on my laptop



juracist
24th June 2012, 14:10
Application is fully functional only on my laptop, and on other computers it fails with part of its functionality.
It starts on every computer (windows 64- and 32- bit), and some parts of it can be executed, but problem is the main part.
I suspect problem is here, within sorting elements of QList.




for(events_it = eventi.begin(); events_it!=eventi.end(); events_it++) {
temp_event = *events_it;
//if type==0, we access size of the event above, and set it to this event
if(temp_event->getType() == 0) {
Event *temp_event2;
events_it2 = events_it;
events_it2--;
temp_event2 = *events_it2;
long s = temp_event2->getSize();
temp_event->setSize(s);
}
}


These are iterators i use:

QList<Event*>::iterator events_it;
QList<Event*>::iterator events_it2;



This is list i use:

QList<Event*> eventi;

Object Event, which is inside QList:


class Event
{
public:
// Constructors
Event(long a, long s, long t,short tip);
Event(long a, long t, short tip);

private:
long address;
long size;
long time;
short type;
};



Application is written under Windows 7 Professional (64-bit).

Build settings:
7893

wysota
24th June 2012, 14:23
What kind of incorrect behaviour do you observe?

juracist
24th June 2012, 15:18
If you want to summarize the work of my application..
1) it reads xml, parse it and save into list of Events, then sort this list, calculate points from sorted events, save it to binary file and finally plots the graph from calculated points

OR

2) if there is already binary file created during case 1), points are read from binary file and drawn as graph.


So, on my laptop, app works in both cases of use, but on other computers it can only read correct binary (case 2), but cannot perform case1.
Some steps of case 1 are incorrect, in my opinion, it fails during sorting..

wysota
24th June 2012, 15:31
How did you implement sorting?

juracist
24th June 2012, 15:42
1st code snippet from 1st post - here's problem, its ok on my laptop and on other computers it fails..

wysota
24th June 2012, 15:53
I don't see sorting in there.

juracist
24th June 2012, 16:05
sorry, firstly i use QStableSort to sort the list, and then this code snippet to access size property of Event (list element).
Iteration through list is implemented with iterators and for loop, firstly it finds element with property type == 0, then with other iterator it goes up for one position and gets size property from above element and finally sets that size to first iterator (with type==0).

I didn't mention usage of QStableSort - it goes well, i checked. But problems appear in code i pasted here.

wysota
24th June 2012, 16:41
sorry, firstly i use QStableSort to sort the list,
What comparison function are you using? Please show us the exact call to qStableSort along with the lessThan implementation you use with it.

juracist
24th June 2012, 18:39
qStableSort(eventi.begin(),eventi.end(),sortAddres s);

bool sortAddress(Event *left, Event *right){
return (left->getAddress() < right->getAddress());
}

wysota
24th June 2012, 19:46
And what your first code snippet is meant to do? Because it seems it searches for event of type 0 and then assigns it the value of "size" of a previous item. Which by the way will fail immediately if the first element in the list has type = 0.

juracist
24th June 2012, 20:13
If you have patience and time, download exe file of my app, and try to run it (only for windows :))
Application (https://dl.dropbox.com/u/14984020/MemPlotTest.rar)

Then, open xml file from same folder, and, if everything is ok, graph should be drawn..
.bin file will be created in same folder, but not good file, only with couple of nulls..
I also attached bin file that is created under my enviroment and if you try to open it, it should draw graph..

So, you'll see there is a problem only with reading xml file, not bin file.
Steps while drawing graph from xml is following:
1. parsexml - OK
2. sortAddress - OK
3. getSize(code snippet from above) - FAIL (checked by printing elements from list into text file)
4. sortTime
5. correctOrder (something like getSize)
6. calculatePoints (create points from CORRECT list of elements)
7. drawGraph

wysota
24th June 2012, 20:19
Sorry, Linux user here :) Still, my question about what your code snippet is meant to do remains unanswered.

juracist
24th June 2012, 20:40
It does exactly what you wrote above. Only, problem isn't first element's property type=0, because it is 1 for sure.

Here is whole sorting process, i dont know, maybe problem is somewhere else:

if(!fileSorted){
qStableSort(eventi.begin(),eventi.end(),sortAddres s);

QList<Event*>::iterator events_it;
QList<Event*>::iterator events_it2;

for(events_it = eventi.begin(); events_it!=eventi.end(); events_it++) {
temp_event = *events_it;
if(temp_event->getType() == 0) {
Event *temp_event2;
events_it2 = events_it;
events_it2--;
temp_event2 = *events_it2;
long s = temp_event2->getSize();
temp_event->setSize(s);
}
}

qStableSort(eventi.begin(),eventi.end(),sortTime);

for(events_it=eventi.begin(); events_it!=eventi.end(); events_it++) {
temp_event = *events_it;
events_it2 = events_it;
events_it2++;
if(events_it2!=eventi.end()) {
Event *temp_event2 = *events_it2;
if(temp_event->getTime() == temp_event2->getTime()) {
if((temp_event->getType() == 1) && (temp_event2->getType() == 0)) {
*events_it = temp_event2;
*events_it2 = temp_event;
}
}
}
}
}

wysota
24th June 2012, 20:50
Your first loop can be replaced with a simpler one:


const s = eventi.size();
for(int i=1;i<s;++i) {
if(eventi[i]->getType() == 0) eventi[i]->setSize(eventi[i-1]->getSize());
}

Your second loop, can be replaced with the following:

for(int i=0;i<s-1;++i) {
if((eventi[i]->getTime() == eventi[i+1]->getTime()) && (eventi[i]->getType() ==1) && (eventi[i+1]->getType() == 0)) qSwap(*eventi[i], *eventi[i+1]); // optionally you might need to ++i here
}

The problem might be in my inlined comment. Since I don't know what you are trying to achieve with the above code, it is hard for me to say whether it is correct or not. I would suggest to get rid of all those iterators in favour of indexes to make sure incorrect use of iterators doesn't influence the result.

juracist
24th June 2012, 23:26
Thank you very, very much!!! :)))))
You don't know how important it is to me, it was driving me crazy for days!
Problem was that i taken some parts of code from previous version (which wasn't in Qt), assuming it'll work as before.

But now i have another question (since I know you're linux user :D).
What do I do to make this app usable on linux too?
It shouldnt be so hard since Qt is supposed to enable portability and platform independence?

Once again, thanks man!!! :D

wysota
24th June 2012, 23:38
Thank you very, very much!!! :)))))
You don't know how important it is to me, it was driving me crazy for days!
Problem was that i taken some parts of code from previous version (which wasn't in Qt), assuming it'll work as before.
So it works now? What was the problem?



But now i have another question (since I know you're linux user :D).
What do I do to make this app usable on linux too?
It shouldnt be so hard since Qt is supposed to enable portability and platform independence?

In theory you just need to [cross]compile it for Linux but it really depends on if you used any non-portable code in your program.

juracist
24th June 2012, 23:52
I just changed my old code with that you wrote here, tried on my laptop - it worked, then on PC - surprise, it works for the first time on other computer :))
It seems these iterators or something was problem..
Tomorrow I'll test it on couple of other computers to see if this is really working..

wysota
24th June 2012, 23:58
I suspect this was wrong:


*events_it = temp_event2;
*events_it2 = temp_event;