PDA

View Full Version : access the widget dynamically



mohanakrishnan
26th November 2009, 13:17
hi
im displaying many buttons dynamically in the application based on the count from the
database.each button has name.when a query is processed a button name is received.
so i need to highlight the corresponding button in the front end application..
how to do ??either a cast from string to qpushbutton possible??
or finding the buttons in the front end with the given name??
can any one help??
thanks in advance!!!:crying::confused:

nish
26th November 2009, 13:26
there are several ways... but if i understood correctly.. on creation of buttons you can use a QHash

QHash<QString, QPushButton*> hash;
QString name = getNameFromSomeWhere();
QPushButton * btn = new QPushButton(name,this);
hash.insert(name,btn);

and so on

Lykurg
26th November 2009, 13:30
Or you can use QObject::findChild():
QPushButton *button = parentWidget->findChild<QPushButton *>("button1");

mohanakrishnan
26th November 2009, 13:33
hi mrdeath
i ll try wat u said ,and then come back..
thanks a lot:):)

mohanakrishnan
26th November 2009, 13:37
hi Lykurg
thanks a lot it worked well.
thanksss:D:D

qtcentre is great