我创建了一个 .gif 文件 https://drive.google.com/file/d/18wHorsxHpfXZc2xm-iEuMG4McsOT-f85/view?usp=sharing
我正在 QMovie 的帮助下添加 git
QLabel* progressIcon = new QLabel(this);
QMovie* progressMovie = new QMovie("Progress_Animation.gif"); // path is correct
progressIcon->setMovie(progressMovie);
progressIcon->setFixedSize(18, 18);
progressIcon->show();
progressMovie->start();
if (!progressMovie->isValid()) {
qDebug() << "MOVIE is NOT valid"; // SEE THIS LOG
} else {
qDebug() << "MOVIE is valid";
}
我读了这个问题Qt中的GIF动画 并将 qgif.dll 添加到我的 .exe 文件所在的文件夹中,但没有帮助
我的代码有什么问题?
当您使用相对路径应用程序基于
current directory
构建真实路径时,根据具体情况可以是任何路径,您假设它是您的源目录或exe所在的目录,并且您的假设是错误的。
试试这个。
QDir dir(".");
qDebug() << dir.absolutePath();
qDebug() << QFile("Progress_Animation.gif").exists();
使用绝对路径
QString path = QDir(qApp->applicationDirPath()).filePath("Progress_Animation.gif")