QHash<int, QWidget*> and qobject_cast to determine the type.
Hi,
Thanks for your reply. I've decided to use a QObjectList which I populate in the if statements, where additionally I set the proper object names used later to identify the object "type" (image, string etc.). Works pretty well.
Regards,
Bill
It might be better to use QList<QWidget*> - it's better for you than QList<QObject*> because you can use the widget interface without any casting. If you want to stick with QObjectList, then you don't need it at all - at any time you can call QObject::children() on the parent widget (or the layout - you'd have to check that out) that will return you a QObjectList of its children.
QList<QString, QMetaObject>. Store the classes meta objects and then use QMetaObject::newInstance to create new instances.
It's nice to be important but it's more important to be nice.
Hi,
Thanks for the QMetaObject hint - I'll look at it in detail...
Another problem I have is that I create an object and add it to a QScrollArea like this:
Qt Code:
scrollAreaWidgetContents->layout()->addWidget(date);To copy to clipboard, switch view to plain text mode
What would be the best way to remove objects from the QScrollArea, which have a pointer stored in a QList<QWidget*>?
I've tried
but end up with a segfault.Qt Code:
for(int i=0;i<formElements.length();++i) scrollAreaWidgetContents->layout()->removeWidget(formElements.at(i));To copy to clipboard, switch view to plain text mode
Thanks for your help,
Reagards,
Bill
I think I found a solution.
After a bit of RTFM,
Qt Code:
while(!formElements.isEmpty()) delete formElements.takeFirst();To copy to clipboard, switch view to plain text mode
works well.
Regards,
Bill
Does qDeleteAll works as well?
It's nice to be important but it's more important to be nice.
Bookmarks