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,
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
}
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
QGraphicsScene * ImageScene = new QGraphicsScene(); //! create a graphics scene
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
QStringList Filter, PathFile; //! create new strings
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
}
To copy to clipboard, switch view to plain text mode
In mainwindow.cpp contains
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()));
QThread *AdsTimeThread = new QThread(this); // init this timer thread
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()));
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.
Bookmarks