[SOLVED]Qvector Problem instansiate Thanks ALL
-
Do other containers or QVector with other type cause crash?
-
My h.file
@#ifndef GLOBALPARAMS_H
#define GLOBALPARAMS_H
#include <QVector>
#include <QList>
#include <QTime>
#include <clpresetloadstestvalues.h>class GlobalParams
{
public:
GlobalParams();
~GlobalParams();
enum Tester {Starttest, Loadtest, Batterytest, ParallellToMains, MainsFailureTEst, PresetLoadsTest , Notest};void setTest(int); int getTest(); void testRunning(bool ); bool getTestRunning(); void setNBState(int s); void setGBState(int s); void setRunningState(int s); void setRunningMode(int s); int getNBState(); int getGBState(); int getRunningState(); int getRunningMode(); void addValuesToLoadsTestTemp(int,int,int); double getRandomNumbers(float max, float min); QString roundnumbers(double dNumber);
private:
int testTyp;int NBState; int GBState; int RunningState; int RunningMode; bool TestRunning; QVector <ClPresetLoadsTestValues> presetVector;
};
@in my cpp file
@void GlobalParams::addValuesToLoadsTestTemp(int kw, int min, int sec)
{
ClPresetLoadsTestValues p;
p.setKW(kw);
p.setMin(min);
p.setSec(sec);if (presetVector.isEmpty()) qDebug() << "Empty"; else qDebug() << "SIZE " << presetVector.size() ; presetVector.append(p); qDebug() << "appendad";
}
@
My h.file to the object I want to save
@class ClPresetLoadsTestValues
{
public:
ClPresetLoadsTestValues();
ClPresetLoadsTestValues(int k, int m, int s);
~ClPresetLoadsTestValues();//set
void setKW(int k);
void setMin(int k);
void setSec(int k);//get
int getKw();
int getMin();
int getSec();private:
int kw;
int min;
int sec;};
@
I tried with a Struct also but same crash -
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