Results 1 to 3 of 3

Thread: Display widgets recursive

  1. #1
    Join Date
    Jul 2015
    Location
    Austria
    Posts
    20
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    3

    Question Display widgets recursive

    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:
    Qt Code:
    1. ModulTreeWidget::ModulTreeWidget(int col, int row, QTreeWidget *parent, Viewer *v):
    2. QTreeWidget(parent)
    3. {
    4. currentRow=row;
    5. currentCol=col;
    6. currentId=0;
    7. if(v)
    8. {
    9. connect(v,SIGNAL(startView()),this,SLOT(startPresentation()));
    10. }
    11. }
    12.  
    13. ....
    14.  
    15. void ModulTreeWidget::addModule(BaseWidget *b)
    16. {
    17. baseWidgets.push_back(b);
    18. }
    19.  
    20. ....
    21.  
    22. void ModulTreeWidget::startPresentation()
    23. {
    24. if(baseWidgets.size()== 0) return;
    25. currentId=-1;
    26. showNext();
    27. }
    28.  
    29. void ModulTreeWidget::showNext()
    30. {
    31. ++currentId;
    32. if(currentId<baseWidgets.size())
    33. {
    34.  
    35. qDebug()<<"ID: "<<QString::number(currentId)<<"Duration: "<<baseWidgets[currentId]->duration*1000;
    36. baseWidgets[currentId]->displayContent();
    37. QTimer::singleShot(baseWidgets[currentId]->duration*1000+100, this, SLOT(showNext()));
    38.  
    39. }else
    40. {
    41. this->startPresentation();
    42. }
    43. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Display widgets recursive

    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).

  3. #3
    Join Date
    Jul 2015
    Location
    Austria
    Posts
    20
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    3

    Default Re: Display widgets recursive

    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
    Qt Code:
    1. QTimer::singleShot(baseWidgets[currentId]->duration*1000+100, this, SLOT(showNext()))//after this 100ms
    To copy to clipboard, switch view to plain text mode 
    it should display the next. I can´t post all displayWidget() methods because that would be too much code(>1000 rows).

Similar Threads

  1. Qt Creator Display QWT widgets in QTcreator (Ubuntu)
    By Julieng031 in forum Qt Tools
    Replies: 0
    Last Post: 24th August 2013, 14:51
  2. How to display 2 widgets on the same space?
    By schmimona in forum Qt Programming
    Replies: 5
    Last Post: 11th August 2011, 13:18
  3. How to display Widgets in the midle of a Window
    By revellix in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2011, 15:48
  4. Replies: 2
    Last Post: 2nd November 2010, 16:52
  5. Replies: 6
    Last Post: 3rd January 2008, 10:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.