Unsolved my program has unexpectedly finished in QCustomPlot set name
-
Hi everyone. I have a struct which i show you in below.
typedef struct list_item { char isim[24]; int idx; int chart_no; int tip; // 1: float, 2: int, 3: char, 4 string // QLineSeries seri; int graph_no; QCPGraph *gr; }list_item;
I want to achive QCustomPlot graphs and set a name to them. I've written this code for it
zs_gps[idx_gps].gr->setName(zs_gps[idx_gps].isim);
When i run it, my program has unexpectedly finished. When i debug i saw that in this sentence it crashed.
void QCPAbstractPlottable::setName(const QString &name) { mName = name; ///in here it crashed }
What am i doing wrong?
-
@firsnur96 Is gr pointer properly initialized (pointing to a valid QCPGraph instance)?
-
@jsulm I thought that, in this sentence i initialized
zs_gps[idx_gps].gr->setName(zs_gps[idx_gps].isim);
-
@firsnur96 said in my program has unexpectedly finished in QCustomPlot set name:
zs_gps[idx_gps].gr
Where do you initialize
gr
? -
@firsnur96 said in my program has unexpectedly finished in QCustomPlot set name:
in this sentence i initialized
I don't see any initialisation here...
-
I know that, when i wrote this is already initialize.
I use the same structure in qt charts and it runs.zs_gps[idx_gps].gr
like
zs_gps[idx_gps].seri.setName(zs_gps[idx_gps].isim);
And i dont really understand , what should i initialize.
-
@firsnur96 said in my program has unexpectedly finished in QCustomPlot set name:
And i dont really understand , what should i initialize.
gr
You should have this somewhere:gr = new QCPGraph();
So, do you have it somewhere?
-
@jsulm I wrote it in my cpp file, it gives an error.
use of undeclared identifier gr -
@firsnur96 Please show the code. Also, gr is part of list_item struct, you can't use it just like "gr". The code I posted before is just to illustrate what you need to do, not the exact code...
-
zs_gps[idx_gps].gr = new QCPGraph;
-
- Show you actual relevant code, rather than isolated lines at a time.
- If you get a compilation error, copy & paste the actual message here. Assuming the message includes a line number, tell us which exact line in your code that refers to by checking the line number (not guessing).
- If you get a runtime error on
zs_gps[idx_gps]...
something, use the debugger or aqDebug()
statement on the line immediately preceding this to prove whatzs_gps[idx_gps]
is and the value ofzs_gps[idx_gps].gr
.
-
@firsnur96 said in my program has unexpectedly finished in QCustomPlot set name:
zs_gps[idx_gps].gr = new QCPGraph;
Is this done before zs_gps[idx_gps].seri.setName(zs_gps[idx_gps].isim);?
Instead of wasting time here you could simply debug your app to find out what is happening... -
Hi
You should give the list_item type
a constructor that initializes its members.Having to do it outside is a disaster waiting to happen. (IMHO)
typedef struct list_item { char isim[24]; int idx; int chart_no; int tip; // 1: float, 2: int, 3: char, 4 string // QLineSeries seri; int graph_no; QCPGraph* gr; explicit list_item() : gr(new QCPGraph ) {} /// init } list_item;