PDA

View Full Version : Display widgets recursive



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();
}
}

d_stranz
5th January 2016, 23:08
I don't see any place where you "don't display content" for the current widget before you change to the next. So, all widgets will end up being displayed after the first pass through the loop. showNext() needs to hide the current widget before incrementing the id. (Of course, checking to be sure that the id is not -1 as it would be on the start of the presentation).

Something like this also needs to happen in startPresentation(), because the second time through the loop, the last widget is still visible.

I don't know why it would crash the second time through the loop, unless there is something in your displayContent() method that assumes the widget is not visible and crashes if it is (whic it will be in your current code).

mayrhofer
6th January 2016, 08:13
In the displayContent() methods of my custom widgets are QTimer::singleShot which timeout on duration*1000(seconds).When the timer has timeout it closes the current widget and then the ModulTreeWidget timer has timout after 100ms and


QTimer::singleShot(baseWidgets[currentId]->duration*1000+100, this, SLOT(showNext()))//after this 100ms

it should display the next. I can´t post all displayWidget() methods because that would be too much code(>1000 rows).