gpt4 book ai didi

c++ - 如何使用信号 QMovie::frameChanged(int frameNumber) 发出信号?

转载 作者:行者123 更新时间:2023-11-30 05:11:41 26 4
gpt4 key购买 nike

我想在currentFrameNumber等于frameCount时使用frameChanged(int)发出信号,我的QT版本是4.7.4

QObject::connect(movie,SIGNAL(frameChanged(int)),movie,SLOT(stop()));

QMovieChild.cpp:

class QMovieChild:public QMovie
{

signals:
void newSignal();
public slots:
void onFrameChanged(int frameNumber){
if(frameNumber == this->frameCount()-2)
emit newSignal();
}
};

怪物.cpp:

void Monster::Vanishment()
{
QMovieChild *movie = new QMovieChild();
movie->setFileName("./pikaqiu.gif");
QSize size = this->getLabelPointer()->size();
movie->setScaledSize(size);
this->getLabelPointer()->setMovie(movie);
QMovie::connect(movie,SIGNAL(newSignal()),movie,SLOT(deleteLater()));
QMovie::connect(movie,SIGNAL(frameChanged(int)),movie,SLOT(onFrameChanged(int)));
movie->start();
}

最佳答案

要创建一个信号,类应该继承自 QObject,如果您使用的类是 QWidget,它也是有效的,因为它继承自 QObject。

#ifndef QMOVIECHILD_H
#define QMOVIECHILD_H

#include <QMovie>

class QMovieChild : public QMovie
{
Q_OBJECT
public:
QMovieChild(QObject * parent = 0):QMovie(parent){
connect(this, SIGNAL(frameChanged(int)), this, SLOT(onFrameChanged(int)));
}

signals:
void newSignal();
private slots:
void onFrameChanged(int frameNumber){
if(frameNumber == frameCount()-1){
emit newSignal();
//stop();
}
}

};

#endif // QMOVIECHILD_H

使用:

QMovieChild *movie = new QMovieChild;
movie->setFileName("./pikaqiu.gif");
QMovie::connect(movie,SIGNAL(newSignal()),movie,SLOT(deleteLater()));
QSize size = getLabelPointer()->size();
movie->setScaledSize(size);
getLabelPointer()->setMovie(movie);
movie->start();

关于c++ - 如何使用信号 QMovie::frameChanged(int frameNumber) 发出信号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44938538/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com