灰色矩形而不是飞溅Qt

Grey rectangle instead of the splash Qt

本文关键字:Qt 色矩 灰色      更新时间:2023-10-16

我构建并执行了应用程序(下面的代码),启动屏幕显示灰色,而不是图像。我不知道问题在哪里,虽然图像的路径是正确的。

This is my main.cpp:

#include <QApplication>
#include<QSplashScreen>
#include "mainwindow.h"
#include <unistd.h>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPixmap pixmap(":/images/splash.png");
QSplashScreen splash(pixmap);
splash.setMask(pixmap.mask());  
splash.show();
app.processEvents();
sleep(5);
MainWindow window;
window.show();
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
splash.finish(&window);
return app.exec();
}

有两个选项:

  • 你没有解析和编译资源文件(用rcc解析)
  • 或者您在qrc文件中添加了错误的路径到您的映像(请参阅qt参考资料),或者您根本没有添加

正如我所说的,尝试使用磁盘上的映像。如果显示正常,则是上述问题之一。