QT之实现开机界面的两种方法

1.官方示例

int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
      QPixmap pixmap(":/splash.png");
      QSplashScreen splash(pixmap);
      splash.show();
      app.processEvents();
      ...
      QMainWindow window;
      window.show();
      splash.finish(&window);
      return app.exec();
  }

2.使用定时器

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;

    QPixmap pixmap(":/icon/qt.ico");
    QSplashScreen splash(pixmap);
    splash.show();

    QTimer::singleShot(1500, &splash, SLOT(hide()));
    QTimer::singleShot(2000, &w, SLOT(show()));

    //w.show();

    return a.exec();
}

实质上是一样的,官方的会更好点

发布了19 篇原创文章 · 获赞 8 · 访问量 3224

猜你喜欢

转载自blog.csdn.net/qq_39295354/article/details/104031789