Hi guys..I am trying to display a series of image in qlabel..i dono where i am going wrong. when i click the qpushbutton it displays only the last image rather displaying from beginning. Below is my code
mainwindow.cpp
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
FirstLabel
= new QLabel(this);
FirstLabel->move(0,240);
FirstLabel->resize(this->x()+400,this->y()+240);
FirstLabel->show();
train_button->setText(tr("something"));
train_button->move(200,200);
train_button->show();
connect(train_button, SIGNAL(clicked()),
this, SLOT (PlayImage()));
}
void MainWindow::PlayImage()
{
char* picture[5] = {"D://1.png","D://2.jpg","D://3.jpg","D://4.jpg","D://5.jpg"};
for(int i = 0;i<=4 ; i++){
FirstLabel->setPixmap(pixmapObject);
update();
}
}
MainWindow::~MainWindow()
{
}
#include "mainwindow.h"
QLabel *FirstLabel = NULL;
QLabel *SecondLabel = NULL;
QLabel *ThirdLabel = NULL;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
FirstLabel = new QLabel(this);
FirstLabel->move(0,240);
FirstLabel->resize(this->x()+400,this->y()+240);
FirstLabel->show();
QPushButton *train_button = new QPushButton(this);
train_button->setText(tr("something"));
train_button->move(200,200);
train_button->show();
connect(train_button, SIGNAL(clicked()),
this, SLOT (PlayImage()));
}
void MainWindow::PlayImage()
{
char* picture[5] = {"D://1.png","D://2.jpg","D://3.jpg","D://4.jpg","D://5.jpg"};
for(int i = 0;i<=4 ; i++){
QPixmap pixmapObject(picture[i]);
FirstLabel->setPixmap(pixmapObject);
update();
}
}
MainWindow::~MainWindow()
{
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
#include <string>
#include <QPushButton>
{
Q_OBJECT
public:
~MainWindow();
void updateinfo();
void Play();
public slots:
void PlayImage();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
#include <string>
#include <QPushButton>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
void updateinfo();
void Play();
public slots:
void PlayImage();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
MainWindow w;
w.resize(800,480);
w.show();
return a.exec();
}
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.resize(800,480);
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks