各位前輩你們好
小弟剛踏入Qt/e的世界,因為是自學,所以理解有限。
如今碰到一個問題,想要弄一個自動循環撥放圖片的程式,
但永遠只能撥放第一張,第二張以後的圖片就抓不到了。
因為這個問題卡了一個多禮拜,也一直瘋狂的找google 找百度,
但還是找不到可以解決的方法,所以想請板上的前輩們,
請你們幫小弟看一下,我的程是到底哪個部分有問題。
先謝謝各位前輩。這是主要部分,註解是我自己寫的(有錯請前輩矯正我的觀念)
小弟有附上檔案了,懇請前輩們替小弟解答。
#include "form1.h"
#include <qlabel.h>
#include <qpixmap.h>
#include <qstringlist.h>
#include <qdir.h>
#include <qfileinfo.h>
#include <qtimer.h>
Form1::Form1(QWidget* parent,const char* name):QDialog(parent,name)
{
/*-------------------- 放圖片的位置與大小------------------*/
setCaption("Form1");
TextLabel1 = new QLabel(this,"TextLabel1");
TextLabel1->setGeometry(QRect(5,5,250,250));
TextLabel1->setText(tr("My Label"));
/*--------------------- 顯示圖片的路徑 --------------------*/
filenametext = new QLabel(this, "filenametext");
filenametext->setGeometry(QRect(5,270,240,20));
/*--------------------- QDir ----------------------------*/
QDir d;
d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
// d.setSorting( QDir::Time );//| QDir::Reversed );
d.setPath("/home/wei/test");
d.setNameFilter("*.jpg");
QStringList list = d.entryList();
QStringList::Iterator it = list.begin();
/*---------------------分配記億體空間存放圖片-------------*/
it = list.begin();
number = 0;
i = 0;
for ( it=list.begin(); it!=list.end(); it++)
{
address[number] = (*it).latin1();
number++;
}
/*-----------------------show出圖片------------------------*/
show_picture();
}
Form1::~Form1(){}
void Form1::show_picture()
{
TextLabel1->setPixmap(QPixmap(address[0]));
TextLabel1->setScaledContents(TRUE);
filenametext->setText(address[0]);
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(auto_show_picture()));
timer->start(2000);
}
/*----------------------替換圖片的函式---------------------*/
/*---目前抓不到第一張圖片以後的圖----*/
void Form1::auto_show_picture()//用timer去驅動圖片置換
{
i++;
if(i==number) i=0;
TextLabel1->setPixmap(QPixmap(address));
TextLabel1->setScaledContents(TRUE);
filenametext->setText(address);
}