mayrhofer
5th January 2016, 19:55
So i have a vector(baseWidgets) and i want to display all my custom widgets(parentclass:BaseWidgets) for a certain time(the duration is located in an integer var). After the duration of the 1st element is finished i want to display the 2nd. I want to do this process for all elements which are stored in my vector. After the last element has been displayd the first one should be shown again. When i have 1 element in my vector everything works fine. When i have more than 1 element all widget gets displayed and when it should start from begin again then my program crashes.Maybe someone finds my error.
Here´s a little code-snippet:
ModulTreeWidget::ModulTreeWidget(int col, int row, QTreeWidget *parent, Viewer *v):
QTreeWidget(parent)
{
currentRow=row;
currentCol=col;
currentId=0;
if(v)
{
connect(v,SIGNAL(startView()),this,SLOT(startPrese ntation()));
}
}
....
void ModulTreeWidget::addModule(BaseWidget *b)
{
baseWidgets.push_back(b);
}
....
void ModulTreeWidget::startPresentation()
{
if(baseWidgets.size()== 0) return;
currentId=-1;
showNext();
}
void ModulTreeWidget::showNext()
{
++currentId;
if(currentId<baseWidgets.size())
{
qDebug()<<"ID: "<<QString::number(currentId)<<"Duration: "<<baseWidgets[currentId]->duration*1000;
baseWidgets[currentId]->displayContent();
QTimer::singleShot(baseWidgets[currentId]->duration*1000+100, this, SLOT(showNext()));
}else
{
this->startPresentation();
}
}
Here´s a little code-snippet:
ModulTreeWidget::ModulTreeWidget(int col, int row, QTreeWidget *parent, Viewer *v):
QTreeWidget(parent)
{
currentRow=row;
currentCol=col;
currentId=0;
if(v)
{
connect(v,SIGNAL(startView()),this,SLOT(startPrese ntation()));
}
}
....
void ModulTreeWidget::addModule(BaseWidget *b)
{
baseWidgets.push_back(b);
}
....
void ModulTreeWidget::startPresentation()
{
if(baseWidgets.size()== 0) return;
currentId=-1;
showNext();
}
void ModulTreeWidget::showNext()
{
++currentId;
if(currentId<baseWidgets.size())
{
qDebug()<<"ID: "<<QString::number(currentId)<<"Duration: "<<baseWidgets[currentId]->duration*1000;
baseWidgets[currentId]->displayContent();
QTimer::singleShot(baseWidgets[currentId]->duration*1000+100, this, SLOT(showNext()));
}else
{
this->startPresentation();
}
}