Hi,
I'd like to make a 'quiz' and I assumed I should add the long list of questions and radiobutton answers into a QScrollArea so they could all be seeen by the user. I'm having trouble to populate the scrollarea procedurally. In the Designer, I've been able to add mock-up questions to the scrollarea, but I can't even remove these mock-ups using my C++ code. I assume that if I can delete these children, I will know how to add content too.

I tried iterating over the "children of the scrollbar's widget's layout" (it hurts a little to say that). Here is my code to do that, which has a bad side-effect; the children render in a different place instead of just being deleted. I'd like to know the right way to delete the content of a scrollarea, thanks for any tips!

Qt Code:
  1. QWidget* scrollarea_content = ui->_quiz_scrollarea->widget();
  2. if( scrollarea_content )
  3. {
  4. //what is this? scrollarea_content->children();
  5.  
  6. QLayout* scrollarea_layout = scrollarea_content->layout();
  7.  
  8. if( scrollarea_layout )
  9. {
  10. QLayoutItem *child;
  11. while ((child = scrollarea_layout->takeAt(0)) != 0)
  12. {
  13. delete child;
  14. }
  15. }
  16. }
To copy to clipboard, switch view to plain text mode