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,
Code:
void MainWindow::display_ads()
{
//! this function will display images in qframe.
static int NextImage; //!! declare image count
Reset = &NextImage; //!! move to pointer
if(AdsImageAddress.count() > 0) //! check it no file
{
QPixmap ImageData
(AdsImageAddress.
at(NextImage
));
//! put file in pixmap ui->ImageView->setScene(ImageScene); //! add graphicsview to scene
QGraphicsPixmapItem * AdsImage
= new QGraphicsPixmapItem(ImageData.
scaled(ui
->ads
->width
()-30,ui
->ads
->height
()-30, Qt
::IgnoreAspectRatio, Qt
::FastTransformation));
//! add pixmap to graphicspixmap ImageScene->addItem(AdsImage); //! add scene to graphics view
ui->ImageView->show(); //! show image
NextImage++; //! repeat process
NextImage = (NextImage == AdsImageAddress.count()) ? (0):(NextImage); //! check for image count
}
else //! if no path is found
{
// throw "No PATH Define"; //! throw a exception
Ads_PATH_PROCESS("/home/pi/DataImage"); // set default path
display_ads(); // display ads again.
}
}
void MainWindow
::Ads_PATH_PROCESS(QString PATH
) //! this function make path to image
{
AdsImageAddress.clear(); //! clear the list
QDir AdsDir
(PATH
);
//! get the path
Filter << "*.png" <<"*.jpg" <<"*.jpeg"; //! filter the dir with images
AdsDir.setNameFilters(Filter); //! fileter process
PathFile
= AdsDir.
entryList(QDir::Files |
QDir::NoDotAndDotDot |
QDir::NoSymLinks);
//! get only files
if(PathFile.count() > 0) //! if images are found
{
PATH+="/"; //! add a path variable if missing
foreach
(QString list,PathFile
) //! for each image path {
AdsImageAddress.append(PATH+list) ; //! add path and file name to list
}
}
*Reset = 0; //! reset NextImage so the pointer Reset Data.
#ifdef DEBUG
qDebug() <<"mainwindow.cpp : "<< "Ads PATH: " << PATH <<endl;
#endif
}
In mainwindow.cpp contains
Code:
AdsTime
= new QTimer;
// created a new timer AdsTime->start(); // start the timer
AdsTime->setInterval(ads_window->AdsInterval * 1000); // add interval, by default 1000 = 1sec
AdsTime->moveToThread(AdsTimeThread); // add timer to thread
AdsTimeThread->start();
AdsTimeThread->connect(AdsTime,SIGNAL(timeout()),this,SLOT(display_ads()));
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.
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,
_