Results 1 to 2 of 2

Thread: Slide Show using QGraphicscene

  1. #1
    Join Date
    Mar 2015
    Posts
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Slide Show using QGraphicscene

    I want to show slide show images for every 1 sec(Default).But the application was close completely after 4 Hours.I will explain how i did this?

    I Create a ads_displayprocess.cpp and it contains,
    Qt Code:
    1. void MainWindow::display_ads()
    2. {
    3. //! this function will display images in qframe.
    4.  
    5. static int NextImage; //!! declare image count
    6. Reset = &NextImage; //!! move to pointer
    7. if(AdsImageAddress.count() > 0) //! check it no file
    8. {
    9. QPixmap ImageData(AdsImageAddress.at(NextImage)); //! put file in pixmap
    10. QGraphicsScene * ImageScene = new QGraphicsScene(); //! create a graphics scene
    11. ui->ImageView->setScene(ImageScene); //! add graphicsview to scene
    12. QGraphicsPixmapItem * AdsImage = new QGraphicsPixmapItem(ImageData.scaled(ui->ads->width()-30,ui->ads->height()-30, Qt::IgnoreAspectRatio, Qt::FastTransformation)); //! add pixmap to graphicspixmap
    13. ImageScene->addItem(AdsImage); //! add scene to graphics view
    14. ui->ImageView->show(); //! show image
    15. NextImage++; //! repeat process
    16. NextImage = (NextImage == AdsImageAddress.count()) ? (0):(NextImage); //! check for image count
    17. }
    18. else //! if no path is found
    19. {
    20. // throw "No PATH Define"; //! throw a exception
    21. Ads_PATH_PROCESS("/home/pi/DataImage"); // set default path
    22. display_ads(); // display ads again.
    23. }
    24. }
    25.  
    26. void MainWindow::Ads_PATH_PROCESS(QString PATH)
    27. //! this function make path to image
    28. {
    29.  
    30. AdsImageAddress.clear(); //! clear the list
    31. QDir AdsDir(PATH); //! get the path
    32.  
    33. QStringList Filter, PathFile; //! create new strings
    34.  
    35. Filter << "*.png" <<"*.jpg" <<"*.jpeg"; //! filter the dir with images
    36. AdsDir.setNameFilters(Filter); //! fileter process
    37.  
    38. PathFile = AdsDir.entryList(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks); //! get only files
    39.  
    40. if(PathFile.count() > 0) //! if images are found
    41. {
    42. PATH+="/"; //! add a path variable if missing
    43. foreach(QString list,PathFile) //! for each image path
    44. {
    45. AdsImageAddress.append(PATH+list) ; //! add path and file name to list
    46. }
    47. }
    48. *Reset = 0; //! reset NextImage so the pointer Reset Data.
    49.  
    50. #ifdef DEBUG
    51. qDebug() <<"mainwindow.cpp : "<< "Ads PATH: " << PATH <<endl;
    52. #endif
    53. }
    To copy to clipboard, switch view to plain text mode 

    In mainwindow.cpp contains

    Qt Code:
    1. QThread *AdsTimeThread = new QThread(this); // init this timer thread
    2. AdsTime = new QTimer; // created a new timer
    3. AdsTime->start(); // start the timer
    4.  
    5. AdsTime->setInterval(ads_window->AdsInterval * 1000); // add interval, by default 1000 = 1sec
    6. AdsTime->moveToThread(AdsTimeThread); // add timer to thread
    7. AdsTimeThread->start();
    8. AdsTimeThread->connect(AdsTime,SIGNAL(timeout()),this,SLOT(display_ads()));
    To copy to clipboard, switch view to plain text mode 

    So Is it any wrong with this code?I dont know how it exist after 4 hrs.So i need your help for solve this kind of problem.
    Last edited by anda_skoa; 26th March 2015 at 13:04. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slide Show using QGraphicscene

    Ensure that your scene is only created once and that the pixmap item is only created once and then gets updated with the new image.

    Right now it looks like you are creating a new scene for every image but not deleting the old one, i.e. a massiv memory leak.

    Also, why the thread for the timer?

    Cheers,
    _

Similar Threads

  1. Create slide show
    By iswaryasenthilkumar in forum Newbie
    Replies: 2
    Last Post: 4th December 2014, 11:55
  2. a set of images slide show on a single QLabel
    By lyw8120 in forum Qt Programming
    Replies: 9
    Last Post: 17th March 2014, 13:19
  3. Slide show using QProperty animation
    By mvbhavsar in forum Newbie
    Replies: 0
    Last Post: 10th August 2011, 10:24
  4. slide of frames
    By vinayaka in forum Newbie
    Replies: 3
    Last Post: 18th July 2011, 06:50
  5. slide show
    By jeetu_happy in forum Qt Programming
    Replies: 3
    Last Post: 18th January 2007, 12:21

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.