Results 1 to 2 of 2

Thread: Qt3 to Qt4 with QListIterator<AbstractThing *> it() with QPushbutton

  1. #1
    Join Date
    Jun 2011
    Posts
    23
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Qt3 to Qt4 with QListIterator<AbstractThing *> it() with QPushbutton

    Hi,

    I am converting a Qt3 App to Qt4 (Qt4.7.1).


    I have a class:
    Qt Code:
    1. class AbstractThing : public QPushButton
    To copy to clipboard, switch view to plain text mode 

    In Qt3 I had a
    Qt Code:
    1. class NodeManager : public QObject, QPtrList<AbstractThing>
    To copy to clipboard, switch view to plain text mode 

    I have converted this in Qt4 to
    Qt Code:
    1. class NodeManager : public QObject, QList<AbstractThing*>
    To copy to clipboard, switch view to plain text mode 


    I have a function in NodeManager that looks at the items in the QList, in Qt3 I had
    Qt Code:
    1. void NodeManager::doStuff()
    2.  
    3. AbstractThing *thing;
    4.  
    5. for(thing = first(); thing; thing = next())
    6. {
    7. //stuff
    8. }
    To copy to clipboard, switch view to plain text mode 


    In Qt4 next() is no longer in Qlist so i have decided to use a QListIterator

    Qt Code:
    1. QListIterator<AbstractThing *> it();
    2.  
    3. AbstractThing *thing = first();
    4.  
    5. while (it.hasNext())
    6. {
    7. thing.setDown(false)
    8. }
    To copy to clipboard, switch view to plain text mode 

    But what do i put in the empty ()? I can't put 'this'


    Or will i be better doing a count on the list and a for(int i = 0 .... with item.at(i) etc...


    Thank you
    Tara

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Qt3 to Qt4 with QListIterator<AbstractThing *> it() with QPushbutton

    QListIterator is a Java-style const iterator, which does not require empty(), instead hasNext() has to be used.

    moreover empty() is supposed to be operated on QList, where as hasNext() is supposed to be operated on QListIterator
    There may be many ways to iterate the list, here are 3 possible ways

    1. Java-style iterators (you already use this, fine)
    2. STL-style iterators (slightly faster and more cumbersome to use to than Java-style iterators
    Qt Code:
    1. QList<AbstractThing *>::const_iterator i;
    2. for (i = this->constBegin(); i != this->constEnd(); ++i)...*i...
    To copy to clipboard, switch view to plain text mode 
    3. Plain index based
    Qt Code:
    1. for(int i = 0; i < this->size(); i++)...this.at(i)....
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 4
    Last Post: 3rd August 2010, 12:30
  2. Replies: 0
    Last Post: 22nd February 2010, 09:30
  3. Qpushbutton
    By iamhere in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 04:40
  4. Porting Qt3->Qt4 QListIterator
    By kemp in forum Qt Programming
    Replies: 4
    Last Post: 3rd October 2006, 07:04
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

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.