Hi everybody,
I am having one problem, i am giving you code can you find out where is problem.
header file:
{
Q_OBJECT
public:
MainDialog();
private:
int count;
int listSize;
private slots:
void updateImages();
void animateImage();
};
class MainDialog : public QDialog
{
Q_OBJECT
public:
MainDialog();
private:
QLabel* labelText;
QLabel* labelImage;
QTimer *timer;
QPushButton* startButton;
QPushButton* quitButton;
QSpacerItem* vspacer;
QStringList imagesStrList;
int count;
int listSize;
private slots:
void updateImages();
void animateImage();
};
To copy to clipboard, switch view to plain text mode
src file:
MainDialog
::MainDialog() : QDialog(){
labelText->setText("My Dialog ... !");
hLayout->addWidget(startButton);
hLayout->addWidget(quitButton);
mainLayout->addWidget(labelText);
mainLayout->addItem(vspacer);
mainLayout->addLayout(hLayout);
imagesStrList << ":/images/1.png"
<< ":/images/2.png"
<< ":/images/3.png"
<< ":/images/4.png"
<< ":/images/5.png"
<< ":/images/6.png";
count = 0;
listSize = imagesStrList.size();
connect(timer, SIGNAL(timeout()),this, SLOT(updateImages()));
connect(startButton, SIGNAL(clicked()),this, SLOT(animateImage()));
connect(quitButton, SIGNAL(clicked()),this, SLOT(close()));
//timer->start(400); //[COLOR="#0000FF"] it's working[/COLOR]
resize(320,240);
}
void MainDialog::updateImages()
{
qDebug("update");
labelImage
->setPixmap
(QPixmap(imagesStrList.
at(count
++)));
labelImage->show();
if(count>=listSize){
count=0;
}
}
void MainDialog::animateImage()
{
timer->start(400); //[COLOR="#FF0000"] It's not calling timer slot, I have to srart timer in this slot[/COLOR]
for(int i=0; i<10; i++){
qDebug("LOOP : %d",i);
sleep(1);
}
timer->stop();
}
MainDialog::MainDialog() : QDialog()
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QHBoxLayout *hLayout = new QHBoxLayout;
labelText = new QLabel;
labelText->setText("My Dialog ... !");
labelImage = new QLabel;
vspacer = new QSpacerItem(20, 150, QSizePolicy::Expanding, QSizePolicy::Minimum);
startButton = new QPushButton("Start");
quitButton = new QPushButton("Quit");
hLayout->addWidget(startButton);
hLayout->addWidget(quitButton);
mainLayout->addWidget(labelText);
mainLayout->addItem(vspacer);
mainLayout->addLayout(hLayout);
timer = new QTimer;
imagesStrList << ":/images/1.png"
<< ":/images/2.png"
<< ":/images/3.png"
<< ":/images/4.png"
<< ":/images/5.png"
<< ":/images/6.png";
count = 0;
listSize = imagesStrList.size();
connect(timer, SIGNAL(timeout()),this, SLOT(updateImages()));
connect(startButton, SIGNAL(clicked()),this, SLOT(animateImage()));
connect(quitButton, SIGNAL(clicked()),this, SLOT(close()));
//timer->start(400); //[COLOR="#0000FF"] it's working[/COLOR]
resize(320,240);
}
void MainDialog::updateImages()
{
qDebug("update");
labelImage->setPixmap(QPixmap(imagesStrList.at(count++)));
labelImage->show();
if(count>=listSize){
count=0;
}
}
void MainDialog::animateImage()
{
timer->start(400); //[COLOR="#FF0000"] It's not calling timer slot, I have to srart timer in this slot[/COLOR]
for(int i=0; i<10; i++){
qDebug("LOOP : %d",i);
sleep(1);
}
timer->stop();
}
To copy to clipboard, switch view to plain text mode
main file:
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(resource);
MainDialog dlg;
dlg.show();
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Q_INIT_RESOURCE(resource);
MainDialog dlg;
dlg.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
i have to start my timer in different slot, but it's not calling the timer slot, if i am starting the timer in constructor, it's working fine.
can you tel me where i am doing wrong ?
Bookmarks