hi,
u need to remove the widgets from the layout.void QVector::clear ()
Removes all the elements from the vector and releases the memory used by the vector.
use
Qt Code:
To copy to clipboard, switch view to plain text mode
hope it helps
Thnks
Bala
So, it is as I thought. But what if I do something like that:
Qt Code:
QVector<QPushButton*> btn; btn.clear(); for(int j=0; j<HOW_MANY_BUTTONS; j++) { b->setGeometry(0,0,40,40); btn << b; ui->verticalLayout->addWidget(btn[j],Qt::AlignVCenter); }To copy to clipboard, switch view to plain text mode
Can I then remove item from layout using:
Qt Code:
ui->verticalLayout->removeWidget(btn[i]);To copy to clipboard, switch view to plain text mode
Or maybe different pointer points on that widget?
thanks in advance
best regards
Tomasz
yes surely u canCan I then remove item from layout using ui->verticalLayout->removeWidget(btn[i]);
no its the same pointerOr maybe different pointer points on that widget?
hope it helps
Bala
Tomasz (29th November 2010)
But if I remove that widget from layout, pointer stays in vector? And I can use it again or just remove it from vector too?
thanks in advance
best regards
Tomasz
yes pointer stays in vector, since u didnt remove it from Vector.But if I remove that widget from layout, pointer stays in vector?
yes, surely u can use it again.And I can use it again
if u dont want that widget then remove it from vector too..or just remove it from vector too?
layout and vector are different...
for ur understanding ... vector is holding the widget pointer.
that widget will be added to the layout by addWidget
and removed by removeWidget
hope it helps
Bala
Tomasz (29th November 2010)
One more question to end that thread. I've got my buttons, now I'm connecting them to QSignalMapper:
Qt Code:
QVector<QPushButton*> btn; btn.clear(); for(int j=0; j<HOW_MANY_BUTTONS; j++) { b->setGeometry(0,0,40,40); btn << b; ui->verticalLayout->addWidget(btn[j],Qt::AlignVCenter); connect(btn[j], SIGNAL(clicked()), sigMap, SLOT(map())); sigMap->setMapping(btn[j], j); } connect(sigMap, SIGNAL(mapped(int)), this, SLOT(func(int)));To copy to clipboard, switch view to plain text mode
What will now happen with QSignalMapper if I remove buttons from layout and vector? Should I clean somehow signal mapper? What happen with all connections?
thanks in advance
best regards
Tomasz
If you "remove" buttons from the layout and vector nothing will happen and connections to the mapper will still be maintained. But if you delete the buttons, all their connections will be broken.
From a technical point of view your vector doesn't hold buttons, it holds pointers to buttons. So you are not removing buttons from the vector (or the layout as a matter of fact) but pointers to buttons.
Tomasz (29th November 2010)
So the safest way to do the cleaning is to: remove widgets from layout, then DELETE all created buttons with:
Qt Code:
delete(btn[x]); // btn is vector with pointersTo copy to clipboard, switch view to plain text mode
and at the end - i can safely clear vector, and then connections will be broken, and QSignalMapper will be 'clean'? Yes? And then I can create everything again?
thanks in advance
best regards
Tomasz
It's enough to delete the buttons. They will be taken out of layouts.
Qt Code:
qDeleteAll(btn); btn.clear();To copy to clipboard, switch view to plain text mode
Tomasz (29th November 2010)
One more question - should I use disconnect() to disconnect all signals (from created buttons) from slots.
thanks in advance
best regards
Tomasz
hi,
u should disconnect all the buttons.should I use disconnect() to disconnect all signals
one button's disconnect will disconnect only that signal.
hope it helps
Bala
Bookmarks