I am trying to make a Widget that contains multiple widgets with each a QCustomplot and some Plot Data (QLabel and QPushbuttons). This widget is open from a mainwindow with parent=0
.
I add the subwidgets with a function, but if it is used more than one time it throws an error:
malloc.c:3757: _int_malloc: Assertion `(unsigned long) (size) >= (unsigned long) (nb)' failed.
So heres the code, that leads to this:
Opening the widget, that should contain the subwidgets:
Zeitdatenfenster = new Plotfenster();
Zeitdatenfenster->getZeitData(ausgewaehlteKanaele, *messdaten, double(Anfangszeiteingabe->value()), double(Endzeiteingabe->value()));
Zeitdatenfenster->show();
Zeitdatenfenster is in the MainWindow class header : Plotfenster* Zeitdatenfenster;
Constructor:
Plotfenster::Plotfenster(QWidget *parent) :
QWidget(parent),
ui(new Ui::Plotfenster)
{
ui->setupUi(this);
counter=0;
}
getZeitData( ...)
-function:
void Plotfenster::getZeitData(const std::vector<bool>& Kanalauswahl, const Messdatenverwaltung& messdaten, double Anfangszeit, double Endzeit){
setWindowTitle("Time Data");
int zahler=0;
for(int i = 0; i<Kanalauswahl.size();i++){
if(Kanalauswahl[i]){
Ploteigenschaften* kanalzeit = new Ploteigenschaften();
std::cout << kanalzeit << std::endl;
geplotteteDatenInhalt.push_back(kanalzeit);
geplotteteDatenInhalt[zahler]->setZeitData(messdaten, i,Anfangszeit,Endzeit);
addPlot(geplotteteDatenInhalt[zahler],zahler);
zahler++;
}
}
}
geplotteteDatenInhalt
is a std::vector<Ploteigenschaften*>
,
addPlot()
is the function where the subwidgets are created. Ploteigenschaften
is just a class that stores the data that is plottet and functions to change it.(with the two Qvectors added to the qcustomplot)
AddPlot function:
void Plotfenster::addPlot(Ploteigenschaften* plotDaten, int zahler ){
Plot* aktuellerPlot = new Plot(plotDaten, this);
geplottetes.push_back(aktuellerPlot);
ui->plotcontainer->addWidget(geplottetes[zahler],counter);
counter++;
}
Plot is the subwiget that contains the constuctor:
Plot::Plot(Ploteigenschaften* plotDatens, QWidget *parent) :
QWidget(parent),
ui(new Ui::Plot)
{
ui->setupUi(this);
ui->plotGrid->setColumnStretch(1, 3);
ui->plotGrid->setHorizontalSpacing(20);
derPlot = new QCustomPlot(this);
this->plotDaten = plotDatens;
this->Datensetzten();
}
The programm crashes at the QCustomplot constructor. In Datensetzten the plot is specified:
void Plot::Datensetzten(){
this->setInfoText();
this->setPlot();
this->setSaveButton();
}
void Plot::setPlot(){
derPlot->addGraph();
derPlot->graph(0)->setData(plotDaten->xDaten,plotDaten->yDaten);
derPlot->xAxis->setRange(plotDaten->xUntereGrenze,plotDaten->xObereGrenze);
derPlot->yAxis->setRange(plotDaten->yMinimum-std::abs(plotDaten->yMinimum)*0.01,plotDaten->yMaximum+std::abs(plotDaten->yMaximum)*0.01);
derPlot->xAxis->setLabel(plotDaten->BeschriftungxAchse);
derPlot->yAxis->setLabel(plotDaten->BeschriftungyAchse);
derPlot->xAxis2->setVisible(true);
derPlot->xAxis2->setTickLabels(false);
derPlot->yAxis2->setVisible(true);
derPlot->yAxis2->setTickLabels(false);
ui->plotGrid->addWidget(derPlot,0,1,2,1);
derPlot->show();
}
Sorry for the long post, but I have no idea where the error is located and would be very glad for som ideas.
Thanks!