[SOLVED]Qvector Problem instansiate Thanks ALL
-
I'm using a vector in a different place in my application and there is no problem to use.
-
Check for that: you declare your presetVector like a value, so that constructor of it is called before the constructor of GlobalParams. So may be the object of GlobalParams haven't been instantiated yet?
-
I have tried to do like this also.
@QVector <.theClass> *myVector;
@
and in the constructor of globalparams@myVector = new QVector<theClass>();
@
but same crash ; -
Ok, once again, check if constructor of GlobalParams is called, add there qDebug()<<"anything";
-
It's the first thing I do in my program.
I got a lot of parameters in that object that I use in other places so thats no problem.
-
Please provide a small, complete, compilable and runnable sample program. We can have a look if and where it crashes ourselves then.
-
Now I'm back to my Work and will send a small application with this Vector problem.
I have put some QDebug lines in the code to:But where could I upload the program
-
I think that any file sharing hosting will be suitable. For example try http://rghost.net/
-
look for a file hoster (e.g. gitorious.org, but you need a logon) or any other
-
I have discovered a problem know that is a little confusing.
When I try to append a Object or a struct thats not in the class where the vector is the program crashes but when I put a struct inside the class and append this to the vector it works fine
-
Here is not the TAR file to test
-
Your code works without any crashes. I didn't do any changes though.
-
Try again with this code
I had comment the problem spots in the last code.
The new one is here
"Vectorproblems":http://rghost.net/31386231pls
-
toho71 either you have to read more about C++ or you did horrible typo. Here it is:
@myClass::~myClass()
{
delete this;
}@ -
copy and paste is the to magic words
Ok now it works again.I have to look in my header prj to and see if this is the magic case.
-
in my testcase i do like this in my constructor
@GlobalParams::GlobalParams()
{
testRunning(false);qDebug() << presetVector.isEmpty(); qDebug() << presetVector.size() << " vectorsize and kapacitet =" << presetVector.capacity(); //Create a tempobject for test ClPresetLoadsTestValues p(10,10,10); qDebug() << "create object "; presetVector.append(p); qDebug() << "appendat obj"; qDebug() << presetVector.size() << " vectorsize and kapacitet =" << presetVector.capacity();
}@
and I got this text in my consol
true
0 vectorsize and kapacitet = 0
create ClPresetLoadsTestValues
create object
delete ClPresetLoadsTestValues
appendat obj
1 vectorsize and kapacitet = 1
delete ClPresetLoadsTestValuesAnd later when I try to add a ClPresetLoadsTestValues my program crashes and NO i don't delete the object.
here is my object
@@ClPresetLoadsTestValues::ClPresetLoadsTestValues()
{
qDebug() << "create ClPresetLoadsTestValues";
}ClPresetLoadsTestValues::ClPresetLoadsTestValues(int k, int m, int s)
{
this->kw = k;
this->min = m;
this->sec = s;
qDebug() << "create ClPresetLoadsTestValues";
}ClPresetLoadsTestValues::~ClPresetLoadsTestValues()
{
qDebug() << "delete ClPresetLoadsTestValues";
}//set and getters
@and my func to add the obj
@void GlobalParams::addValuesToLoadsTestTemp(int kw, int min, int sec)
{
ClPresetLoadsTestValues p(kw,min,sec);qDebug() << "try to append"; qDebug() << this->presetVector.size() << " vektorstorlek"; //IT crashes here if (this->presetVector.isEmpty()) qDebug() << "Empty"; else qDebug() << "SIZE " << presetVector.size() ; presetVector.append(p); qDebug() << "appendad";
}
@
-
Can you make another tarball?
-
it gonna be big with many files but maybe only the files in the spec region and it will not compile.
I'll try -
You should provide only source files. Do not include object files (and autogenerated moc_, ui_, qrc_*) in the tarball.
-
Here it is
the two files with this problem
"myFiles":http://rghost.net/31396481