View Full Version : translating qt3 querylist to qt4
cinemaster
21st June 2007, 19:32
Hi,
I have the following code in qt3 that I've been trying unsuccessfully to port to qt4 using qlist and findchildren. How would the following translate to qt4?
QObject *obj2;
QObjectList *l2 = MyTabPage->queryList("QPushButton","leHS*",true,false);
QObjectListIt it4( *l2 ); // iterate over the buttons
while ( (obj2 = it4.current()) != 0 ) {
qDebug(" Connecting \"%s\"",obj2->name());
connect( ((QLineEdit *)obj2), SIGNAL(NumberChanged(double)),SLOT(CalcProceeds()) );
// for each found object...
++it4;
}
Thanks!
Gene
jacek
21st June 2007, 22:47
This should work:
foreach( CustomLineEdit *obj, MyTabPage->findChildren< CustomLineEdit * >( QRegExp( "leHS.*" ) ) ) {
qDebug() << " Connecting" << obj->objectName();
connect( obj, SIGNAL(NumberChanged(double)), SLOT(CalcProceeds()) );
}
Replace CustomLineEdit with your custom line edit's class name.
cinemaster
22nd June 2007, 07:59
This should work:
foreach( CustomLineEdit *obj, MyTabPage->findChildren< CustomLineEdit * >( QRegExp( "leHS.*" ) ) ) {
qDebug() << " Connecting" << obj->objectName();
connect( obj, SIGNAL(NumberChanged(double)), SLOT(CalcProceeds()) );
}
Replace CustomLineEdit with your custom line edit's class name.
This looks really good, and quite a difference in structure. Does this find all children & grandchildren, or just children? From my understanding, findChildren finds all, but I only wanted the direct children.
Thanks for pointing out the "foreach" addition as well, I hadn't known about that.
Thanks for the help!
Gene
jacek
22nd June 2007, 12:29
Does this find all children & grandchildren, or just children? From my understanding, findChildren finds all, but I only wanted the direct children.
According to the docs the search is recursive and it seems that there is no other way than:
if( obj->parent() == MyTabPage ) {
...
}
cinemaster
23rd June 2007, 04:14
According to the docs the search is recursive and it seems that there is no other way than:
if( obj->parent() == MyTabPage ) {
...
}
I was afraid of that.
Thanks for the help,
Gene
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.