Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a requirement to display gif with a label(from widget.cpp). The label is present in another ui(displayads.ui). I am able to display an image with this label but the gif is not displaying. The image & gif I am assigning from widget.cpp. displayads.ui contains two labels, one for image display and one for gif display. For this I have commented Ui::displayads *ui & destructor from displayads.h & displayads.cpp. The code is given below.

I am closing this objdispads after 3 seconds but my requirement is to close this from another function of Widget. Can you please help me to display GIF and closing this objdispads from another function.

What I have tried:

As above mentioned

Widget.cpp
C++
///////////// for image display  //////////////

void Widget::Displayads()
{
  displayads *objdispads = new displayads(this);
    
  QPixmap pix1("/root/img.png");
  objdispads->ui->adlabel1->setPixmap(pix1);
  objdispads->ui->adlabel1->setScaledContents( true );
  objdispads->ui->adlabel1->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );

          //////////   code for gif display    /////////

    QMovie *movie = new QMovie("/root/swachbt.gif");
    if (!movie->isValid())
    {
        qDebug()<<"Movie is Inavlid";
    }
    objdispads->ui->adlabel2->setMovie(movie);
    movie->start();

    objdispads->show();

    QCoreApplication::processEvents();
    QCoreApplication::processEvents();

    sleep(3);
    objdispads->close();
    objdispads->deleteLater();
}

displayads.cpp
C++
#include "displayads.h"
#include "ui_displayads.h"

displayads::displayads(QWidget *parent) :
QWidget(parent),
ui(new Ui::displayads)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
    ui->adlabel1->setAutoFillBackground(true);
//  ui->adlabel2->setAutoFillBackground(true);
}

//displayads::~displayads()
//{
// delete ui;
//}

displayads.h
C++
#ifndef DISPLAYADS_H
#define DISPLAYADS_H

#include <qwidget>

namespace Ui {
class displayads;
}

class displayads : public QWidget
{
    Q_OBJECT
    
public:
    explicit displayads(QWidget *parent = 0);

    Ui::displayads *ui;

//    ~displayads();
    
private:
//    Ui::displayads *ui;
};

#endif // DISPLAYADS_H
Posted
Updated 17-May-19 5:10am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900