Results 1 to 5 of 5

Thread: translating qt3 querylist to qt4

  1. #1
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default translating qt3 querylist to qt4

    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?

    Qt Code:
    1. QObject *obj2;
    2. QObjectList *l2 = MyTabPage->queryList("QPushButton","leHS*",true,false);
    3. QObjectListIt it4( *l2 ); // iterate over the buttons
    4.  
    5. while ( (obj2 = it4.current()) != 0 ) {
    6. qDebug(" Connecting \"%s\"",obj2->name());
    7. connect( ((QLineEdit *)obj2), SIGNAL(NumberChanged(double)),SLOT(CalcProceeds()) );
    8. // for each found object...
    9. ++it4;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!

    Gene

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: translating qt3 querylist to qt4

    This should work:
    Qt Code:
    1. foreach( CustomLineEdit *obj, MyTabPage->findChildren< CustomLineEdit * >( QRegExp( "leHS.*" ) ) ) {
    2. qDebug() << " Connecting" << obj->objectName();
    3. connect( obj, SIGNAL(NumberChanged(double)), SLOT(CalcProceeds()) );
    4. }
    To copy to clipboard, switch view to plain text mode 
    Replace CustomLineEdit with your custom line edit's class name.

  3. The following user says thank you to jacek for this useful post:

    cinemaster (23rd June 2007)

  4. #3
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: translating qt3 querylist to qt4

    Quote Originally Posted by jacek View Post
    This should work:
    Qt Code:
    1. foreach( CustomLineEdit *obj, MyTabPage->findChildren< CustomLineEdit * >( QRegExp( "leHS.*" ) ) ) {
    2. qDebug() << " Connecting" << obj->objectName();
    3. connect( obj, SIGNAL(NumberChanged(double)), SLOT(CalcProceeds()) );
    4. }
    To copy to clipboard, switch view to plain text mode 
    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

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: translating qt3 querylist to qt4

    Quote Originally Posted by cinemaster View Post
    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:
    Qt Code:
    1. if( obj->parent() == MyTabPage ) {
    2. ...
    3. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: translating qt3 querylist to qt4

    Quote Originally Posted by jacek View Post
    According to the docs the search is recursive and it seems that there is no other way than:
    Qt Code:
    1. if( obj->parent() == MyTabPage ) {
    2. ...
    3. }
    To copy to clipboard, switch view to plain text mode 
    I was afraid of that.
    Thanks for the help,
    Gene

Similar Threads

  1. Translating a QStringList
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 18th January 2007, 11:06
  2. Translating Date and Month Names
    By Jimmy2775 in forum Qt Programming
    Replies: 8
    Last Post: 2nd November 2006, 16:35
  3. Replies: 2
    Last Post: 13th September 2006, 09:11
  4. problem translating & rotating text
    By impeteperry in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2006, 19:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.