Results 1 to 3 of 3

Thread: how to make this into a loop

  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default how to make this into a loop

    header file
    Qt Code:
    1. public:
    2. QStringListIterator *iterator;
    3. QTimer *timer;
    4.  
    5. public slots:
    6. void slide();
    7.  
    8. private:
    9. QLabel *picture;
    To copy to clipboard, switch view to plain text mode 

    cpp file
    Qt Code:
    1. picture = new QLabel(this);
    2.  
    3. picture->setGeometry(QRect(781,2,475,360));
    4. picture->show();
    5. QDir dir("/home/dev/ttm/images/");
    6. dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    7. QStringList files = dir.entryList();
    8. QStringList fileNames;
    9.  
    10. foreach (QString f, files)
    11. fileNames << (dir.absolutePath() + QDir::separator() + f);
    12.  
    13. iterator = new QStringListIterator(fileNames);
    14.  
    15. timer = new QTimer(this);
    16. connect(timer, SIGNAL(timeout()), this, SLOT(slide()));
    17. timer->start(6000);
    18.  
    19. void mediazone::slide()
    20. {
    21.  
    22. if(iterator->hasNext())
    23. {
    24. picture->clear();
    25. picture->setPixmap(QPixmap(iterator->next()));
    26. picture->show();
    27.  
    28. }
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 

    I want to make this loop once it hits the last file in the list how would i go about doing so thanks

  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: how to make this into a loop

    I want to make this loop once it hits the last file in the list how would i go about doing so thanks
    Qt Code:
    1. void mediazone::slide()
    2. {
    3. if(iterator->hasNext())
    4. {
    5. picture->clear();
    6. picture->setPixmap(QPixmap(iterator->next()));
    7. picture->show();
    8. }
    9. else
    10. {
    11. iterator->toFront();
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to make this into a loop

    i forgot about the else

    thanks that works perfect

Similar Threads

  1. Replies: 4
    Last Post: 6th August 2011, 01:40
  2. Replies: 6
    Last Post: 10th March 2011, 16:42
  3. Replies: 1
    Last Post: 5th March 2011, 18:23
  4. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 16:31
  5. Replies: 1
    Last Post: 15th December 2010, 13:20

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.