QT设计开机启动画面,【转载】亲测成功
main.cpp
#include <QApplication> #include <QSplashScreen> #include <QPixmap> #include <mainwindow.h> #include <QDebug> #include <QElapsedTimer> #include <QDateTime> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPixmap pixmap("img/logo.jpg"); QSplashScreen screen(pixmap); screen.show(); screen.showMessage("LOVE", Qt::AlignCenter, Qt::red); #if 0 int delayTime = 5; QElapsedTimer timer; timer.start(); while(timer.elapsed() < (delayTime * 1000)) { app.processEvents(); } #endif #if 0 QDateTime n=QDateTime::currentDateTime(); QDateTime now; do{ now=QDateTime::currentDateTime(); app.processEvents(); } while (n.secsTo(now)<=5);//5为需要延时的秒数 #endif MainWindow window; window.show(); screen.finish(&window); return app.exec(); }
mainWindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QTextEdit> #include <QDateTime> #include <QCoreApplication> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { QTextEdit *edit=new QTextEdit; edit->setText("Splash Example!"); setCentralWidget(edit); resize(600,450); QDateTime n=QDateTime::currentDateTime(); QDateTime now; do{ now=QDateTime::currentDateTime(); QCoreApplication::processEvents(); } while (n.secsTo(now)<=5);//5为需要延时的秒数 ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } #include "mainwindow.h" #include "ui_mainwindow.h" #include <QTextEdit> #include <QDateTime> #include <QCoreApplication> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { QTextEdit *edit=new QTextEdit; edit->setText("Splash Example!"); setCentralWidget(edit); resize(600,450); QDateTime n=QDateTime::currentDateTime(); QDateTime now; do{ now=QDateTime::currentDateTime(); QCoreApplication::processEvents(); } while (n.secsTo(now)<=5);//5为需要延时的秒数 ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; }
成功完成启动logo