You can do that but it is bad style. A temporary variable should be local and not a class member:
for (int i = 0; i < inputVal; i++)
{
Device *temp = new Device;
myList.append(temp);
}
There is even no need to use a temporary variable:
for (int i = 0; i < inputVal; i++)
{
myList.append(new Device());
}
To access the last item just call
myList.takeLast()
myList.last()
.
The cleanup function should be called from the destructor of the class that owns
myList
and might be called from elsewhere if required:
MyClass::~MyClass()
{
DeleteAllDevices();
}
void MyClass::DeleteAllDevices()
{
while (!myList.isEmpty())
delete myList.takeFirst();
}